Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Tilemap tiles' assigned GameObjects instantiate in edit mode and again in play mode

Discussion in '2D' started by EmmaEwert, May 27, 2019.

  1. EmmaEwert

    EmmaEwert

    Joined:
    Mar 13, 2014
    Posts:
    25
    I'm working on an importer for Tiled which imports directly to Unity's built-in Tilemap (and other components).

    I assign prefabs through script on import to some of the tiles' gameObject property. Because I also create and populate a Tilemap on import, this immediately instantiates the prefab on import, which is fine.

    However, upon entering Play Mode, the assigned prefabs get instantiated again, while the ones instantiated in Edit Mode also stick around. This effectively means I have two instances of each prefab at each tile.

    Is there any way to only instantiate the Tile's assigned gameObject in Edit (or Play) Mode, but not both?

    I'd prefer not to roll my own tile prefab assignment and not having to handle instantiation myself, considering Unity already has the functionality built-in.
     
  2. EmmaEwert

    EmmaEwert

    Joined:
    Mar 13, 2014
    Posts:
    25
    Note: Tile.StartUp and Tile.GetTileData both seem to be called during Edit Mode and Play Mode, so it doesn't seem to me that I can just use either to defer assigning the gameObject property.

    As well, Application.isPlaying returns false both in Edit Mode and as Play Mode loads the tiles.
     
    Last edited: May 27, 2019