Author Topic: MissingReferenceException inside NGUI  (Read 2236 times)

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
MissingReferenceException inside NGUI
« on: July 01, 2014, 09:46:21 AM »
MissingReferenceException: The object of type 'UILabel' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Component.get_transform () (at C:/BuildAgent/work/aeedb04a1292f85a/artifacts/EditorGenerated/UnityEngineComponent.cs:20)
UIRect.get_cachedTransform () (at Assets/NGUI/Scripts/Internal/UIRect.cs:196)
UIRect.get_parent () (at Assets/NGUI/Scripts/Internal/UIRect.cs:239)

I get this randomly after updating to 3.6.6
Edit:
(and on 3.6.4(did not get it yet on 3.6.6)).
Also i get (randomly) similar errors on UItween components.(il add trace when next time i get this on UItween)
« Last Edit: July 01, 2014, 10:10:44 AM by Fireball14 »

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
Re: MissingReferenceException inside NGUI
« Reply #1 on: July 01, 2014, 10:26:09 AM »
Ok traced this error to this code:
Label.gameObject is turned off on Start.
  1.     void Awake()
  2.     {
  3.         BattleMain.OnEquationChange += OnOnEquationChange; //<- Activates while Label.gameObject is not active, so i think this is what causing problem. Still need to do some testing.
  4.     }
  5.  
  6.     private void OnOnEquationChange()
  7.     {
  8.         Label.text = "2+2";
  9.     }
  10.  

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
Re: MissingReferenceException inside NGUI
« Reply #2 on: July 01, 2014, 12:07:17 PM »
Ok i think i found problem.
Before 3.6.6 this did not meter.
But on 3.6.6 you cant send two same events on same object in one update.
I dont know why =\ But removing one of event senders fixes problem.
Il test more tomorrow, but for now 1 hour testing confirmed this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: MissingReferenceException inside NGUI
« Reply #3 on: July 02, 2014, 04:00:51 AM »
Never use Awake for anything other than initializing local script's values.

Read up on what Unity is intended Awake for. It's basically the constructor, called before the hierarchy and other scripts are processed.

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
Re: MissingReferenceException inside NGUI
« Reply #4 on: July 02, 2014, 06:50:06 AM »
Ok that helped! Thx you!
All i did is made

  1.     void OnEnable()
  2.     {
  3.         BattleMain.OnEquationChange += OnOnEquationChange;
  4.     }
  5.  
  6.     void OnDisable()
  7.     {
  8.         BattleMain.OnEquationChange -= OnOnEquationChange;
  9.     }
  10.