Search Unity

Place a tile with SetTile without destroying the instantiated gameobject

Discussion in '2D' started by AidinD, Aug 25, 2020.

  1. AidinD

    AidinD

    Joined:
    May 3, 2017
    Posts:
    4
    Is there a way to change a tile programmatically? The way I am trying to do it now is using the SetTile method which works except it destroys the GameObject the previously placed Tile instantiated.

    Example: I have a CustomTile1 which is a RuleTile and instantiates myGameObject and we have another CustomTile2 which does NOT instantiate a gameobject.

    CustomTile1 is placed in the tile editor. During runtime I click on a tile and use SetTile on the clicked tile to change it into CustomTile2. But I want to keep myGameObject. Instead it seems SetTile destroys any gameobjects previously instantiated by a tile.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Sorry, I don't think this is possible right now without special scripting. To do this, you will need to script a custom Tile and override the
    TileBase.StartUp
    method to handle the creation of the GameObject for the Tile.

    We will check out adding functionality to handle this properly.
     
    AidinD likes this.
  3. Mr_FJ

    Mr_FJ

    Joined:
    Sep 4, 2013
    Posts:
    7
    Hey sorry if it's not good custom to resurrect an old post, but are there any news on this, or do you have any tips on how to prevent the destruction of the old gameobject?