Author Topic: Unity 4.5.5p3 Weirdness  (Read 10792 times)

vexir

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 47
    • View Profile
Unity 4.5.5p3 Weirdness
« 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:



When in Play Mode:



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.
« Last Edit: November 07, 2014, 04:55:56 AM by vexir »

ammarz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #1 on: November 07, 2014, 02:51:26 PM »
I think this related to the issue discussed in this post, 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 ...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #2 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

ammarz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #4 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.

ammarz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #5 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #6 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.

ammarz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #7 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. }

bdominguez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #8 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 4.5.5p3 Weirdness
« Reply #9 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."