Hello Guest

Author Topic: Disappearing TileMaps when Committed  (Read 4628 times)

hemdanw

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Disappearing TileMaps when Committed
« on: April 16, 2014, 06:42:23 am »
Hi,

I am building a game where I generate a world by instantiating tilemap prefabs from a pool. To create those prefabs, I first create the tilemaps in the hierarchy then drag/drop them into a prefab. If the tilemap in the hierarchy was not committed, the prefabs work fine and I can see the tilemaps when I run the game. If the tilemap in the hierarchy was committed, the prefab appears as an empty tilemap??

I saw this post, but I assume it is a different case from mine... believe I should keep the "prefab" entry under the "Data" tab of the editor set to "none" in my case.

http://2dtoolkit.com/forum/index.php/topic,1900.msg9364.html#msg9364

I also found this posting on your forum:

http://2dtoolkit.com/forum/index.php/topic,1524.msg7361.html#msg7361

If I am instantiating tilemap prefabs, do I still need to call the "LoadSceneAdditive" method... I'm not sure what it is used for exactly. I am not loading any tilemaps across different scenes so maybe I don't need this method??

The last paragraph of the above post also suggested trying "ForceBuild()"? Is it suggesting I keep the prefab tilemaps uncommitted and use "ForceBuild()" to commit them at runtime? Wouldn't this affect performance?

Thanks for the help,
   hemdanw

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Disappearing TileMaps when Committed
« Reply #1 on: April 16, 2014, 10:13:55 am »
Hi,

There is no way to instantiate the tile map data prefab, so basically it will need to be generated at runtime. You can call force build if you want, which will do what it needs to. It isn't super fast to instantiate like that but is necessary as Unity will not save meshes, etc. in a prefab.

The alternative, more efficient method is to save the tile map chunks as scenes, then LoadSceneAdditive. Once you have the built tilemap, you can simply Instantiate the render data object instead of the tile map, it should work as long as the master exists somewhere.

You should consider caching all of this on startup and not Instantiate large tile map chunks at runtime.