Search Unity

Tile removal callback

Discussion in '2D' started by MikeBaldwin, Jul 17, 2018.

  1. MikeBaldwin

    MikeBaldwin

    Joined:
    Jun 27, 2013
    Posts:
    3
    Is there any callback when a tile is removed? I'm struggling with attached GameObjects to my custom tile not being removed when the tile is overwritten. I can instantiate them with StartUp(), but how do I know when the tile is destroyed?
     
  2. MikeBaldwin

    MikeBaldwin

    Joined:
    Jun 27, 2013
    Posts:
    3
    Never mind, I think I've figured it out.
    I was under the assumption that you had to instantiate the GameObject yourself when setting it to the tile data. But according to the (sparse) documentation on the subject, it seems that the TileMap instantiates it automatically on SetTile(). Thus, it seems it should destroy the object automatically as well, when overwritten.
    My problem was I apparently had two clones of the same GameObject and I didn't realize it until I had already posted this question. I blame my inexperience with Unity's tile map system :)
    At least that's what my experimentation is showing.

    If anyone else has any other insight into it, please let me know.