Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: vexir on November 07, 2014, 04:31:54 AM

Title: Unity 4.5.5p3 Weirdness
Post by: vexir on November 07, 2014, 04:31:54 AM
Hey, I just upgraded to Unity 4.5.5p3. I used to be on p2, and NGUI worked fine. I'm on the latest NGUI from the repository. Now, I see this weirdness:

When in Editor Mode:

(http://i.imgur.com/yEkU3km.png)

When in Play Mode:

(http://i.imgur.com/78in8De.png)

Any idea what's going on there? Makes it kind of tough to edit. Some widgets are fine, but there are two containers that despite their anchors show a 2x2 size. Pressing play pops their size and position to the right place.
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ammarz on November 07, 2014, 02:51:26 PM
I think this related to the issue discussed in this post (http://www.tasharen.com/forum/index.php?topic=11603.0), also it happens with the recent 4.5.5p4.
Unity probably changed a behavior of some sort which broke anchoring inside the editor, I tried investigating and made some dirty fixes, but its still not behaving normally as it should, it seems its caused by mCam in UIPanel being null when worldCorners geter is called but didn't have the time to dive deeper into the code hoping it'll be fixed by either Unity or Aren soon.

A quick workaround is to edit anything in the code to trigger a recompile which gets everything into position, but hitting the play button messes it again ...
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ArenMook on November 07, 2014, 03:16:31 PM
Looked into this. It seems what Unity broke is that before, the call order was:

Awake
OnEnable
OnValidate

Now it's

OnValidate
Awake
OnEnable
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ammarz on November 07, 2014, 03:26:09 PM
Looked into this. It seems what Unity broke is that before, the call order was:

Awake
OnEnable
OnValidate

Now it's

OnValidate
Awake
OnEnable

Ahaa I knew it had something to do with event call orders, but been busy updating other stuff in my game, now that you confirmed it I think I can come up with a quick fix.
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ArenMook on November 07, 2014, 03:47:52 PM
Ok looked into this some more. This is 100% a Unity regression Bug.

OnValidate is no longer affected by Script Execution Order. That's what breaks this. I see no easy way to work around it on my end. Widgets basically get validated up before cameras were awakened and found.
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ammarz on November 07, 2014, 04:35:34 PM
well here's a quick and dirty fix I did and it worked ...

In UIRect I changed this:
  1. protected virtual void OnValidate()
  2. {
  3.         if (NGUITools.GetActive(this))
  4.         {
  5.                 if (!Application.isPlaying) ResetAnchors();
  6.                 Invalidate(true);
  7.         }
  8. }

to this:
  1. protected virtual void OnValidate()
  2. {
  3.         Invoke("delayedOnValidate", 0.0001f);
  4. }
  5. private void delayedOnValidate ()
  6. {
  7.         if (NGUITools.GetActive(this))
  8.         {
  9.                 if (!Application.isPlaying) ResetAnchors();
  10.                 Invalidate(true);
  11.         }
  12. }

I didn't test it that much, but seems to do the trick for now, at least in my case.
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ArenMook on November 07, 2014, 04:44:52 PM
That's not exactly a fix. Invoke() doesn't work at edit time. You are basically removing the OnValidate call altogether in edit time.
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ammarz on November 07, 2014, 05:24:06 PM
That's not exactly a fix. Invoke() doesn't work at edit time. You are basically removing the OnValidate call altogether in edit time.

lol good to know, well here's another dirty workaround, I don't know exactly why it works, but still enables me to quickly edit and test the UI without affecting game code itself.

also in UIRect:
  1. protected virtual void OnValidate()
  2. {
  3.         if (NGUITools.GetActive(this))
  4.         {
  5.                 if (!Application.isPlaying) ResetAnchors();
  6.                 Invalidate(true);
  7.  
  8.                 // the workaround
  9.                 if (mCam == null){
  10.                         mAnchorsCached = false;
  11.                 }
  12.         }
  13. }
Title: Re: Unity 4.5.5p3 Weirdness
Post by: bdominguez on November 10, 2014, 02:18:55 AM
Looked into this. It seems what Unity broke is that before, the call order was:

Awake
OnEnable
OnValidate

Now it's

OnValidate
Awake
OnEnable

Has anyone reported this to Unity? Because if it's in pX that's ok because it's not fully stable and tested but that can't be landed in 4.5.6 or 4.6 stable.
Title: Re: Unity 4.5.5p3 Weirdness
Post by: ArenMook on November 10, 2014, 08:42:26 PM
Yes, I reported it. #646217: "OnValidate is no longer affected by the Script Execution Order, which completely breaks all NGUI users."