Author Topic: UIToggle.current.value is sometimes null in UITogleObject script  (Read 5658 times)

Quarkism

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
UIToggle.current.value is sometimes null in UITogleObject script
« on: November 23, 2013, 05:02:03 PM »
I have a simple tab view. There are 3 toggle buttons and 3 gameobject containers. When I tab back and forth that UIToggle.current is sometimes null on line 56. The issue is sporadic. If I click a tab and see an error log one time and the next time it will work !


Edit I fixed the solution. I referenced the local Toggle in awake and used that to set the value OnToggle. Does anyone else find it weird that you use a static variable to find a attached components value ?
« Last Edit: November 23, 2013, 08:23:12 PM by Quarkism »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle.current.value is sometimes null in UITogleObject script
« Reply #1 on: November 23, 2013, 08:22:24 PM »
Interesting. Might be nesting-related. Change the UIToggledObjects.Toggle function to this:
  1.         public void Toggle ()
  2.         {
  3.                 bool val = UIToggle.current.value;
  4.  
  5.                 if (enabled)
  6.                 {
  7.                         for (int i = 0; i < activate.Count; ++i)
  8.                                 Set(activate[i], val);
  9.  
  10.                         for (int i = 0; i < deactivate.Count; ++i)
  11.                                 Set(deactivate[i], !val);
  12.                 }
  13.         }

Quarkism

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: UIToggle.current.value is sometimes null in UITogleObject script
« Reply #2 on: November 23, 2013, 08:24:34 PM »
That works. Thanks Aren !