Hello Guest

Author Topic: Instantiating tile map prefabs  (Read 6586 times)

GreatBigJerk

  • Newbie
  • *
  • Posts: 6
    • View Profile
Instantiating tile map prefabs
« on: April 28, 2015, 02:47:18 pm »
I was wondering if it was possible to instantiate prefabs containing tile maps and have them render after instantiation. Basically what I want to do is have a small set of pooled tilemaps that I can stick end to end on a scrolling level to create an infinite scrolling level. I've done similar things with other tile systems from the asset store, but when I try to instantiate a tile map, the mesh in the mesh filter of my chunks is missing.

Am I doing something wrong, or is it even possible at all?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Instantiating tile map prefabs
« Reply #1 on: April 28, 2015, 03:03:48 pm »
Instantiating the tilemap should work. Make sure you dont have the tilemap render data as a child of the tilemap - it recreates it at runtime when instantiated.

GreatBigJerk

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Instantiating tile map prefabs
« Reply #2 on: May 05, 2015, 06:54:31 pm »
I have the tile map and render data as separate children under a prefab. I can instantiate tilemaps if I set them to be static, but then I can't move them into position after instantiation(so having pooled instances isn't really working). Instantiating non-static prefabs containing tilemaps results in the meshfilter on chunks being empty and nothing getting rendered and no collisions on the mesh collider happening.

Any suggestions?

GreatBigJerk

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Instantiating tile map prefabs
« Reply #3 on: May 05, 2015, 08:55:20 pm »
After looking at it further, it looks like if I don't commit my tile map changes, and leave it like that in the prefab, the mesh is kept. The chunk data is automatically made static though, so it can't be moved. Is there a way to prevent chunks from automatically being made static?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Instantiating tile map prefabs
« Reply #4 on: May 06, 2015, 10:27:42 pm »
If you don't commit the changes, it is no different to not including the tilemap render data. You shouldn't really include those in your prefab as the objects get deleted and recreated as necessary.

What do you mean by the chunks being static? They're just normal gameobjects, they should move just fine?

GreatBigJerk

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Instantiating tile map prefabs
« Reply #5 on: May 07, 2015, 06:04:48 pm »
It's weird, the chunks WERE getting marked as static before, but after tinkering with them, they no longer are. Chances are that I must have done that while tinkering with things. I'm now able to move the prefabs around, and it's working quite nicely.

As for not committing changes, it's the only way that I can get prefabs containing tilemaps to actually have mesh data. I had to play around to figure out the proper steps to get it working right: To get it to work I drag the prefab I'm working with into a scene, commit the changes (this will add the mesh data and make the map visible), hit edit, and then apply the changes to the prefab. If I just commit the changes and apply to the prefab, my mesh data will be empty in the mesh filter and mesh collider when instantiating the prefab.

 I feel like I'm exploting some bug, which is a bit worrisome, but it's working so far...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Instantiating tile map prefabs
« Reply #6 on: May 11, 2015, 12:36:42 am »
The disappearing - if it is what I think it is - a new Unity 5 issue. This will be fixed in the next release.

GreatBigJerk

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Instantiating tile map prefabs
« Reply #7 on: May 13, 2015, 05:48:33 pm »
Actually I'm using 4.6.2f1, maybe it was a change built for Unity 5 that was also implemented in 4?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Instantiating tile map prefabs
« Reply #8 on: May 14, 2015, 05:34:22 pm »
Thats a good question - I don't know when that API function was added into Unity. I assumed it was Unity 5 as it was new, but I'll try and work out when it happened.