Hello Guest

Author Topic: Weird issues when tk2dTilmap script is inside prefab  (Read 4831 times)

arche-san

  • Newbie
  • *
  • Posts: 2
    • View Profile
Weird issues when tk2dTilmap script is inside prefab
« on: March 11, 2015, 05:18:06 pm »
Hey guys,

I'm working on a top down/zelda video game using TK2D to design grounds and walls. Each room on this game is designed using a TK2D Tilemap script. Then I convert rooms into prefabs and I group them into the same scene to test the final dungeon.

I've got weird disturbing issues when I stored a tk2dTileMap script into a prefab object. The tilemap render data related to script is often (not always) duplicated and the tilemap informations are not saved properly even when I apply the settings of the prefab.

To prevent this, I've made two hacks :
- I destroy the renders data game object with same name at start of Awake method (consequences: the tilemap game object name must be unique)
- I save the prefab automatically when the tilemap is rebuilt in edit mode

I search a better way to fix this. Any ideas ? :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Weird issues when tk2dTilmap script is inside prefab
« Reply #1 on: March 12, 2015, 11:13:01 am »
You're not putting the render data in there as well are you? You shouldn't - if you are it could cause the kind of weird things you're describing....

arche-san

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Weird issues when tk2dTilmap script is inside prefab
« Reply #2 on: March 12, 2015, 02:39:50 pm »
Nope, I'm not putting the render data in the prefabs containing the TK2D tilemap script. I've tried and there are anothers weird issues indeed. I consider the render data as an external generated part of the tilemap and for me it doesn't need to be saved into a prefab object, it must be reload or regenerated each time the tilemap is modified. :)

I've got despite everything duplicated render data. It seems that the overridden properties of the prefab are not saved properly. The prefab instance is reset to its original state (from project ressources) instead when the scene start running. The renderData property in the TK2D tilemap script is null and does not match with the already existing render data gameobject available on my scene. That's why today I commit the prefab after any rebuilt and I regenerate the tilemap render data.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Weird issues when tk2dTilmap script is inside prefab
« Reply #3 on: March 12, 2015, 11:32:26 pm »
Hmmm. thats confusing. It should save this correctly. Is it reproducible with a new prefab? If so please send me the steps and I should be able to investigate.

FabienC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Weird issues when tk2dTilmap script is inside prefab
« Reply #4 on: March 13, 2015, 05:08:42 pm »
Hi,

I know about this issue.

A quick way to see it :
- Create a game object with a tilemap component
- Set the sprite collection, the tile data and the editor data
- Save the game object as a prefab
- In paint mode, draw something and commit (do not apply on prefab !!!)
- Launch the scene : the tilemap draws nice
- End the scene : the tilemap is already in paint mode Oo
- Commit : BOOM ! All modifications lost.

It's not the only case things start getting messed up :
- Create a game object with a tilemap component
- Set the sprite collection, the tile data and the editor data
- Save the game object as a prefab
- Erase the render data gameobject associated to your tilemap
- Launch the scene : the render data is regenerated
- Launch the scene once more : a new render data is regenerated
- Launch the scene once more : a new render data is regenerated
- Launch the scene once more : a new render data is regenerated
...

It seems that any modification on the gameobject overriding a prefab's property (the bold-text values on other gameobjects) are lost when playing your scene. The link between prefab and render data is always set back to "null". Any modification on tilemap not applied to its parent prefab is lost. Sometime, layer gameobjects, chunk gameobjects or collider components start duplicating for the same reasons.

For now, I managed to work around this problem but it get sometime really annoying. As prefab system is a core feature of Unity, this problem sounds like a serious issue.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Weird issues when tk2dTilmap script is inside prefab
« Reply #5 on: March 13, 2015, 10:45:46 pm »
Hmmm... maybe its not recording the change for some reason. Can you post a repro case please.
Unity keep changing how the prefab system works, its changed 3 times in the past 3 releases so I have no idea whats broken now.

Also what version of Unity is this on?

FabienC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Weird issues when tk2dTilmap script is inside prefab
« Reply #6 on: March 16, 2015, 12:09:29 pm »
I posted you two repro cases just above.

It was the case on Unity 4.6. It's still broken on Unity 5.