How do I replace a tile with a prefab?

(Retrogue1) #1

There is probably a very simple solution to this, but I can’t find it for the life of me.

All I want to do is replace certain tiles placed in my map with prefabs that have been created in unity.

The “Appearing Blocks” section in the “Mega Dad Adventures” tutorial seems kind of what I want, but it seems overly complicated to just replace with a prefab, and I don’t understand where the example code is supposed to be placed.

I’m not even really sure if I need code for this or if it is just a setting somewhere in tiled/tiled2unity/unity.

Any suggestions would be much appreciated.

(Seanba) #2

Hi Retrogue1, here’s some pointers to help.

First off, if you are replacing tiles then you really want to be dealing with tile objects and not tile layers (in Tiled). The “appearing blocks” stuff you’re talking about does this. Basically, in Unity scripting, we want to replace one GameObject with another during the import process.

BTW this tutorial may be of some use as well ( At the very least it will help you automatically create tile objects from tile layers from within Tiled.

Lastly, anytime you are doing something with custom scripting then you want that in “your own” code. In other words, outside of the Tiled2Unity folders. That’s just to keep things clean and separated.

(Oh, and keep in mind that Unity requires all editor scripts to be inside a folder named “Editor”. That’s something that often trips people up.)

The scripting part of things can be a bit intimidating at first to people new to programming but if you want specialized behavior in your game then there really isn’t a way around it. But let me know if there’s something a bit more specific you want explained and I’ll see what I can do.