Author Topic: NGUI 3.0.8f7 update issue : currentTouch = null  (Read 3239 times)

kitgui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
NGUI 3.0.8f7 update issue : currentTouch = null
« on: January 14, 2014, 04:31:27 PM »
I after updating, I found that the placement of some menu elements are a little off - no problem, I can just move them again - and UIButtonColor is now throwing a NullRefException.

I pinned the issue down to line 171 in UIButtoncolor.cs :
  1. else if (UICamera.currentTouch.current == gameObject && UICamera.currentScheme == UICamera.ControlScheme.Controller)

I haven't yet gone and looked at how NGUI has changed that I would now be getting this issue, just thought I would post it in case someone knows a quick fix.

Thanks in advance!  ;D

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: NGUI 3.0.8f7 update issue : currentTouch = null
« Reply #1 on: January 14, 2014, 06:37:49 PM »
From the NGUI ReadMe:

3.0.8 f7
- FIX: UIPanel's "explicit" render queue option should now work correctly.
- FIX: UITweener.Play should behave better with duration of 0.
- FIX: NGUITools.FindCamera will prioritize the Main Camera over others (fix for Unity Water).
- FIX: Null exception fix in UIKeyBinding.

Perhaps it's the Camera-fix?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.8f7 update issue : currentTouch = null
« Reply #2 on: January 14, 2014, 07:18:47 PM »
UIButton script expects to know where the event came from. If you're triggering the button's logic yourself, you likely didn't set UICamera.currentTouch value to anything. I don't remember if f7 had the fix for UIKeyBinding that would cause this. If not, then change its Update function to the following and it should fix it:
  1. void Update ()
  2.         {
  3.                 if (keyCode == KeyCode.None || !IsModifierActive()) return;
  4.  
  5.                 if (action == Action.PressAndClick)
  6.                 {
  7.                         if (UICamera.inputHasFocus) return;
  8.  
  9.                         UICamera.currentTouch = UICamera.controller;
  10.                         UICamera.currentScheme = UICamera.ControlScheme.Controller;
  11.                         UICamera.currentTouch.current = gameObject;
  12.  
  13.                         if (Input.GetKeyDown(keyCode))
  14.                         {
  15.                                 UICamera.Notify(gameObject, "OnPress", true);
  16.                         }
  17.  
  18.                         if (Input.GetKeyUp(keyCode))
  19.                         {
  20.                                 UICamera.Notify(gameObject, "OnPress", false);
  21.                                 UICamera.Notify(gameObject, "OnClick", null);
  22.                         }
  23.                         UICamera.currentTouch.current = null;
  24.                 }
  25.                 else if (action == Action.Select)
  26.                 {
  27.                         if (Input.GetKeyUp(keyCode))
  28.                         {
  29.                                 if (mIsInput)
  30.                                 {
  31.                                         if (!mIgnoreUp && !UICamera.inputHasFocus)
  32.                                         {
  33.                                                 UICamera.selectedObject = gameObject;
  34.                                         }
  35.                                         mIgnoreUp = false;
  36.                                 }
  37.                                 else
  38.                                 {
  39.                                         UICamera.selectedObject = gameObject;
  40.                                 }
  41.                         }
  42.                 }
  43.         }

kitgui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: NGUI 3.0.8f7 update issue : currentTouch = null
« Reply #3 on: January 14, 2014, 07:49:26 PM »
You are right that I'm handling input myself, I needed each player to have their own controller-specific menu.

Sadly, the copy of UIKeyBinding I have contains the same Update() function you posted, but the issue still persists.

Could it have something to do with UIButtonColor executing before UIKeyBinding?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.8f7 update issue : currentTouch = null
« Reply #4 on: January 14, 2014, 09:10:43 PM »
As I mentioned, if you are doing your own input logic then you will need to do what I did in the UIKeyBinding class:
  1. UICamera.currentTouch = UICamera.controller;
  2. UICamera.currentScheme = UICamera.ControlScheme.Controller;
  3. UICamera.currentTouch.current = gameObject;
...before calling any OnPress, OnClick, or other events.