Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: vexir on May 21, 2014, 05:44:50 PM

Title: Buttons Stopped Working After Upgrade
Post by: vexir on May 21, 2014, 05:44:50 PM
Hi there,

I've just upgraded our project from 3.0 to 3.6 and all of a sudden, our map screen stopped working. None of the buttons that sit on top of the map are working any longer (hover, press, click, etc all broken). Nothing else except NGUI has changed.

I haven't done any serious debugging into this yet but a quick breakpoint reveals that the wrong object is being caught by the touch - it's the map background itself that is being caught. It has a box collider on it because you drag on the map background to move a scroll view, but it should be sitting underneath the rest of the buttons so I'm not sure why the new version of NGUI is causing the map to register as being on top.
Title: Re: Buttons Stopped Working After Upgrade
Post by: ArenMook on May 21, 2014, 05:51:27 PM
Check UICamera's event type. it should be set to UI.

Edit: If you have the latest Pro, that's "3D UI". Alternatively you can switch to 2D UI if you're going to be using Box 2D colliders.
Title: Re: Buttons Stopped Working After Upgrade
Post by: vexir on May 29, 2014, 12:14:44 PM
It is set to 3D UI. I'm on the latest from the Git repository. I don't understand why upgrading NGUI would cause the layering of our widgets or the way that NGUI perceives which widget should receive a touch.

Most of my screens stopped working because there are box colliders on the backing of the screen (the frame, to prevent screens underneath the top screen from receiving events). For some reason, it's seeing the backing as being on top of everything else. The backing has a depth of 9, the buttons have depth 44.

Do you know why the backing colliders would catch touches in 3.6 when they wouldn't in 3.0?
Title: Re: Buttons Stopped Working After Upgrade
Post by: vexir on May 29, 2014, 01:04:46 PM
Some debugging reveals that in UICamera's Raycast function, this code is perhaps causing problems?

  1.                                 for (int b = 0; b < hits.Length; ++b)
  2.                                         {
  3.                                                 GameObject go = hits[b].collider.gameObject;
  4.                                                 UIWidget w = go.GetComponent<UIWidget>();
  5.  
  6.                                                 if (w != null)
  7.                                                 {
  8.                                                         if (!w.isVisible) continue;
  9.                                                         if (w.hitCheck != null && !w.hitCheck(hits[b].point)) continue;
  10.                                                 }
  11.                                                 else
  12.                                                 {
  13.                                                         UIRect rect = NGUITools.FindInParents<UIRect>(go);
  14.                                                         if (rect != null && rect.finalAlpha < 0.001f) continue;
  15.                                                 }
  16.  
  17.                                                 mHit.depth = NGUITools.CalculateRaycastDepth(go);
  18.  
  19.                                                 if (mHit.depth != int.MaxValue)
  20.                                                 {
  21.                                                         mHit.hit = lastHit;
  22.                                                         mHit.go = lastHit.collider.gameObject;
  23.                                                         mHits.Add(mHit);
  24.                                                 }
  25.                                         }
  26.  

Although the loop goes through all the proper game objects and "go" becomes the backing and the button and whatever else we hit, the line

  1.                                                         mHit.go = lastHit.collider.gameObject;

causes only the backing to get added to the mHits array over and over again.

So by the time it gets to the sort line below that block, the mHits array just has multiple instances of the backing in it, and none of the other widgets got added.
Title: Re: Buttons Stopped Working After Upgrade
Post by: ArenMook on May 30, 2014, 01:52:53 PM
That section currently reads:
  1.                                                 if (mHit.depth != int.MaxValue)
  2.                                                 {
  3.                                                         mHit.hit = hits[b];
  4.                                                         mHit.go = hits[b].collider.gameObject;
  5.                                                         mHits.Add(mHit);
  6.                                                 }
...in the Pro repository, and 'mHit' is a struct, meaning the value that gets added to the 'mHits' list has a copy, not the original.
Title: Re: Buttons Stopped Working After Upgrade
Post by: Monarky on August 19, 2014, 02:10:57 PM
I just tryed to update my project. My map also stoped working the buttons on my 3d map just quit working after an hour of playing with it. I completely deleted my NGUI folder in my project while in another scene and re downloaded it to make sure all the scripts were right. But still no success. Glad I made a backup before upgrading . I know all my 2d menus on another camera worked fine but my 3d did not.