Author Topic: Sprites in prefab reverting  (Read 7458 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprites in prefab reverting
« Reply #15 on: May 20, 2014, 01:42:38 PM »
Hmm... no matter what I try I can't seem to reproduce it on my end anymore.

1. New scene.
2. ALT+SHIFT+S to add a sprite.
3. Added UIButton to it.
4. Saved the sprite as a prefab.
5. Changed the sprite's "Normal" state on the UIButton, Apply the prefab. Changes stay.
6. Changed the sprite on the UISprite, Apply. Changes stay.
7. Selected the prefab itself, changed the sprite from there. Works as expected.

What are you doing differently?

boofcpw

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: Sprites in prefab reverting
« Reply #16 on: May 20, 2014, 05:47:09 PM »
Instead of adding the button to a prefab, try create a prefab from the buttons parent panel (as if it were a window prefab or something)

Then, try to copy the button, and change the new copied buttons sprite.

Apply the window prefab, and the second button should revert.

Basically
-Create panel
-Add button below panel
-Save panel as prefab
-Copy button
-Change new copied buttons sprite
-Apply panel prefab
boom!

I believe the act of copying the button is what breaks it. Perhaps there is some reference to the original hanging around?

Heres where it gets super weird. If you duplicate the panel prefab, after making a change and getting the sprite to revert itself on application of the panel prefab, the new panel prefab actually has the correct sprite!

boofcpw

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: Sprites in prefab reverting
« Reply #17 on: May 20, 2014, 06:08:20 PM »
I have created a project to help you reproduce the issue

https://www.dropbox.com/s/l9cdqancbls3hf4/NGUI_Button_Test_Two_No_NGUI.zip

The steps required are:
-open test scene
-import ngui
-in the scene hierarchy, copy the button in window
-change the new buttons sprite
-apply window
-(new button should revert)
-from this point, duplicate the window prefab in the project view
-add the new, duplicated window to the scene. It has the correct sprite (weird)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprites in prefab reverting
« Reply #18 on: May 20, 2014, 10:54:43 PM »
Thanks! It helped me track down the issue. Open up UIButtonColor (UIButton's base class) and add [System.NonSerialized] in front of all the protected variables:
  1.         [System.NonSerialized] protected Color mStartingColor;
  2.         [System.NonSerialized] protected Color mDefaultColor;
  3.         [System.NonSerialized] protected bool mInitDone = false;
  4.         [System.NonSerialized] protected UIWidget mWidget;
  5.         [System.NonSerialized] protected State mState = State.Normal;
...seems to fix it.

boofcpw

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: Sprites in prefab reverting
« Reply #19 on: May 20, 2014, 11:14:40 PM »
Hey, thanks

I have tried the fix in two project which had the issue and it seems to have not fixed either of them.

Its probably fair to blame super consistent solar radiation (or something) for this issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprites in prefab reverting
« Reply #20 on: May 21, 2014, 11:07:58 AM »
Still? Hm. I noticed the issue was popping up only when the UIButton was enabled. When disabled, everything would work as expected, which is what led me to make those changes. After doing so everything seemed to stick. Perhaps try adding [System.NonSerialized] to UISprite.mSpriteSet as well? We're trying to work around a bug in Unity here (private values should not be serialized, yet Unity serializes them for prefabs), and adding NonSerialized seems to be the only work-around.

boofcpw

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: Sprites in prefab reverting
« Reply #21 on: May 24, 2014, 08:34:07 PM »
I can confirm this no longer happens in the latest NGUI update. Thanks for that!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Sprites in prefab reverting
« Reply #22 on: May 25, 2014, 02:17:18 PM »
Detail: Unity serializes it, because the debug inspector can see private members and shows their values. If they're nonserialized it does not. Sucks that it leads to weird caching errors like these.