Author Topic: Prefab instances not saving atlas references?  (Read 4304 times)

electrodruid

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 48
    • View Profile
Prefab instances not saving atlas references?
« on: April 05, 2013, 06:40:44 AM »
I have a weird problem. So, my GUI is split across a few different scenes (a frontend, a HUD to load additively over every level, a pause menu, etc), and all the sprites in all of the scenes all use the same reference atlas. Well, sort of... In order to have a script be able to actually change the reference atlas to point at the right SD/HD version, I have to have an instance of the reference atlas in each scene. All of the sprites in that scene point to the scene's reference atlas, and there's a script attached to the atlas in each scene to change the reference depending on the device resolution. With me so far?

So the problem comes when I have prefabs in my scene. Say I've got a prefab that contains a sprite. If I created the prefab in Scene A, then it will work just fine in Scene A, but if I try to use it in Scene B it won't work because the sprite needs to be referring to Scene B's atlas. I've got an editor script which automates the process of changing sprites in a scene to point at that scene's atlas, which appears to work fine. So I can open Scene B, import my prefab, run my editor script to make the prefab sprites use Scene B's atlas, look at the prefab in the inspector to confirm that the atlas has been changed, and then save the scene. The problem is if I then load up different scene and then go back to Scene B (or quit and re-open Unity), it hasn't saved the changes and the prefab sprite is using the wrong reference atlas again. Normally when you change something the new value shows up in bold, but that doesn't seem to happen with atlases :( Any ideas?

electrodruid

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 48
    • View Profile
Re: Prefab instances not saving atlas references?
« Reply #1 on: April 05, 2013, 07:49:31 AM »
Doh! Found the problem. My script to change the texture atlases wasn't calling NGUIEditorTools.RegisterUndo. I didn't think I'd need it (didn't care much about being able to undo my script), but tried adding it anyway, and the changes started getting saved. I wondered what magic was going on, so I went to look at RegisterUndo, and found this:

  1. /// <summary>
  2. /// Create an undo point for the specified objects.
  3. /// This action also marks the object as dirty so prefabs work correctly in 3.5.0 (work-around for a bug in Unity).
  4. /// </summary>

That would explain it, then  :D