Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    30
    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:
    30
    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