Hello Guest

Author Topic: Tilemap as Prefab for Infinite or Dynamic Terrain  (Read 3826 times)

dividity

  • Newbie
  • *
  • Posts: 2
    • View Profile
Tilemap as Prefab for Infinite or Dynamic Terrain
« on: September 10, 2015, 06:59:52 pm »
Hi,

I'm making a game that requires my terrain (tilemap) to be very big, and procedurally generated. The shape of the level I can change by means of SetTile and such, and is working like a charm, but now I want to be able to dynamically add tilemaps to the scene according to the position of the player.
I saw in a post a recommendation to use LoadLevelAdditiveAsync, but with this approach, unless I understood incorrectly, I'd have to have a scene for each tilemap I want to add.

So, what I tried was creating a prefab of the tilemap and instantiating it at runtime, but this has a bizarre behavior (possibly I'm doing something wrong). The newly created tilemap appears on the hierarchy but the Render Data doesn't. I tried Build() and ForceBuild().

I'd really appreciate it if someone could point me in the right direction on how to achieve this.
Or, if someone could point to a solution to building large worlds without me having to write my own tilemap.

Thanks in advance!!!


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap as Prefab for Infinite or Dynamic Terrain
« Reply #1 on: September 10, 2015, 11:13:12 pm »
Instantiating tilemaps at runtime should work in the latest version of tk2d, there were issues in older versions... In any case its way way better to do it using additive levels. Even if all you do is write an editor script to automatically create and maintain the scenes for you. It really is so much more efficient, and you need a scene to edit the tilemap anyway, so win-win.

dividity

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Tilemap as Prefab for Infinite or Dynamic Terrain
« Reply #2 on: September 11, 2015, 08:06:21 pm »
Thank you for the reply.

If I understand correctly, with this method I can't generate a, let's say, "infinite tilemap". I'd have to create a certain number of scenes beforehand and then load them additively where I want.

Is this correct or am I missing something?

Thanks again,

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap as Prefab for Infinite or Dynamic Terrain
« Reply #3 on: September 15, 2015, 02:41:22 pm »
You can create an infinite tilemap by creating the different scenes, loading them in additively as needed and then move into position... Once something goes "out of view" delete it, or better yet pool it.