I have set up my gameobject to be instantiated for the base tile, but it does not instantiate it on painting on the tilemap. When you enter play mode, it instantiate when painting or hovering over the exiting tile.
I have set all my flags to none, so it isn’t the cause of “instantiate only runtime”. The gameobjects does not instantiate unless I manually paint again during play mode or hover over them.
This seems strange and must be a bug? Or have I missed something?
The tile I am painting is just base tile class and I have manually assigned the gameobject by using debug mode in the inspector.
Could share an image of the Inspector of GameObject you are using to be instantiated and the Tile? Other details such as the version of the Unity Editor would be helpful as well.
Alternatively, you can file a bug with the Unity Bug Reporter and post the case number here, we wouuld be happy to investigate there as well!
Coming to think about it… maybe it is instantiating it… but just not visible… even with the gameobject with sprite renderer on it seems to work, there are no gameobjects actually seen in the hierarchy. Are they all hidden by default?
I can confirm that painting the same brush during runtime, does indeed instantiate the game objects and can be seen in the hierarchy, but not during edit mode. The tile flag for “instantiate only during runtime” is not set. During edit mode, it seems to instantiate the gameobject but they do not appear on the hierarchy.
Yes, they are hidden. This is to prevent duplicates from being saved to the Scene, especially in Edit Mode, otherwise each time you load the Scene and save it, you will get more and more added to the Scene.
But then during runtime, it needs to instantiate? Problem is it does not instantiate even during runtime.
The painted tile with game object to instantiate should do so at least during run time. But they are not… they only instantiate when i hover over them using paint brush.
Edit2: This solution will instantiate another gameobject on playmode and when instantiated with the tile palette. However, this does not happen with the DontSave flag on.
For anybody that struggled with this, add the following lines of code inside the StartUp() function on the Scriptable Tile.
This code assumes you have already defined your tile prefab on the GetTileData() function.
Refactorings accepted, this is a quick fix. Probably just setting go.hideFlags = HideFlags.None would do the trick. Edit: I meant, setting the hide flags to none and manually updating the hierarchy window should do the trick.
While I’m seeing them instantiated just fine, they seem to be instantiated some time after all Start() methods are called and before the first Update() call, which makes it impossible to do anything during the setup of the tilemap gameobjects.
I noticed the same, and i have an issue setting up the children of a tilemap due to this behavior.
I have a script “A” on the tilemap object, which is the parent of all tiles in that tilemap. Some tiles are prefab instances with a scrip “B” on them. In editor, script A during update obtains all scripts B in children and applies some modifications to prefab instances that have script B on them, these changes vanish when i enter play mode, and i suspect this happens because the tiles get re-instantiated sometime after the start method.
So my question is, when i enter play mode, since i can’t keep the changes in edit time, how would i one-time-update my prefab instances with the script B on them that are instantiated after the start method under the tilemap object, w/o using the update loop and some bools? i don’t really want to have the update loop run on every tile, when it isn’t actually needed.
@ChuanXin
I’m trying to bake a lightmap by using these gameobjects instantiated by tiles but can’t because of these hideflags. Can I disable the hideflags so I can build the lightmap?
If it is not possible I probably need to scrap the gameobjects and write a separate script which instantiates them so it is kind-of important for me.Thanks!
Unfortunately, you would have to manually disable the hide flags through a script before building your lightmap, and enable them after to prevent them from being saved to your scene.
I can do that no problem but where should I search for the instantiated gameobjects? I mean - probably because of the hide flags - the objects are not seeable.
Are they in the same place where they can be found runtime and can be found with a transform.GetChild(index)?
They should be children of the Transform which has the Tilemap component which stores the Tiles that have instantiated them, iterating using transform.GetChild should work.