Author Topic: UIButtonOffset OnHover can be called before Init() is run  (Read 5265 times)

getluky

  • Guest
UIButtonOffset OnHover can be called before Init() is run
« on: February 19, 2013, 03:50:18 PM »
This stacktrace is what I'm getting when I try to use a button to activate and automatically select a default button in another panel, where the other panel begins as deactivated. The order of components is a UIButtonActivate to activate the other panel, then UIButtonKeys.SelectOnClick should automatically select a button in the other panel which has a UIButtonOffset attached.

SelectOnClick ends up setting the selectedObject before the object in question has run Start/Init on its components, which both throws this UnassignedReferenceException and also runs a Tween to Vector3.zero scale since it gets called before mScale is initialized.

Environment is NGUI 2.3.3h and Unity 3.5.7. It sounds similar to this issue: http://www.tasharen.com/forum/index.php?topic=2913.msg15021#msg15021, was this fixed in 2.3.3h in the assetstore?

  1. UnassignedReferenceException: The variable tweenTarget of 'UIButtonOffset' has not been assigned.
  2. You probably need to assign the tweenTarget variable of the UIButtonOffset script in the inspector.
  3. UIButtonOffset.OnHover (Boolean isOver) (at Assets/NGUI/Scripts/Interaction/UIButtonOffset.cs:61)
  4. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  5. UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:644)
  6. UICamera:Highlight(GameObject, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:631)
  7. UICamera:set_selectedObject(GameObject) (at Assets/NGUI/Scripts/UI/UICamera.cs:359)
  8. UIButtonKeys:OnClick() (at Assets/NGUI/Scripts/Interaction/UIButtonKeys.cs:74)
  9. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  10. UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:644)
  11. UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1147)
  12. UICamera:ProcessOthers() (at Assets/NGUI/Scripts/UI/UICamera.cs:990)
  13. UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:790)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #1 on: February 19, 2013, 08:26:29 PM »
So you're basically accessing functions before the script has actually been started. I'll add some checks to this for the next version, but I suggest you reconsider what you're doing so that this doesn't happen.

getluky

  • Guest
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #2 on: February 19, 2013, 08:35:48 PM »
Is this not expected usage? If you add a UIButtonScale or UIButtonOffset to the "DONE" button in your Controller Input example, it triggers this exact behavior.

It happens when SelectOnClick is targeting an inactive button (such as on another panel), and this is exactly what is set up in the Controller Input example.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #3 on: February 19, 2013, 08:38:31 PM »
Try this version.

getluky

  • Guest
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #4 on: February 19, 2013, 08:44:21 PM »
@ArenMook: That works well, thanks! There's an identical issue with UIButtonScale if you have time to apply the same modification there.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #5 on: February 19, 2013, 08:47:23 PM »
I applied it to all UIButton series of scripts.

getluky

  • Guest
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #6 on: February 19, 2013, 08:52:53 PM »
Thanks @ArenMook, as always I appreciate the quick response.

mmuller

  • Guest
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #7 on: February 22, 2013, 04:43:02 PM »
Arenmook,

Any idea when the next update with these changes is due, I am having issues with OnHover when enabling/disabling menus...

Regards,

Mark

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #8 on: February 23, 2013, 02:16:45 AM »
Within 2 days.

mmuller

  • Guest
Re: UIButtonOffset OnHover can be called before Init() is run
« Reply #9 on: February 23, 2013, 04:40:28 AM »
Excellent, looking forward to finalising this menu !