Hello Guest

Author Topic: Tilemap doesn't clear prefabs  (Read 3109 times)

BigDaddio

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Tilemap doesn't clear prefabs
« on: October 07, 2013, 04:11:41 am »
OK maybe I am doing this wrong, I created a sprite prefab, actually a TK2DtiledSprite. I used it in my tilemap by dragging and dropping it into the TileMapData. OK it displays correctly and works well, until I do something like ClearTile(x, y, 0); where the tile is the prefab, it doesn't get cleared.

The only way to remove the tiles are to destroy the gameobject... that is the tile. This is a real pain. I am using prefabs as doors. When a door is hit I can destroy the object, but lets say I redraw the tilemap. It leaves all the old prefabs, they don't get cleared.

Am I correct in the way I am doing this? I want the doors to have a singular trigger. So I created a sprite prefab with a trigger. I then dragged my sprite prefab into the tk2dTileMapData. Maybe there is a better way or a correct way to erase all the tiles in the map other than stepping though a 2D loop and clearing each tile? I do not draw my tilemaps I generate them procedural.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap doesn't clear prefabs
« Reply #1 on: October 07, 2013, 11:20:41 am »
This is intentional.
In this use case you probably want it to disappear - its probably better/easier to attach a script to your prefab do this. In other scenarios automatically deleting doesn't make sense at all - eg. placing enemies that can move, or when you have any more complex relationships between objects.

As mentioned in the other post, it probably makes more sense to spawn these instances yourself if you want to do this exclusively at runtime from code. If you need to clear the entire tilemap, just delete the render data object and call Build on the tilemap once you've modified what you need.