Author Topic: NullReferenceExceptions within TweenScale/TweenPosition.scale mTrans reference  (Read 3799 times)

getluky

  • Guest
I don't know how or why this is happening, but in a complex scene with multiple panels, enabling/disabling panels with NGUITools.SetActive sometimes causes the mTrans property to become null within a TweenScale or TweenPosition script, leading to NullReferenceExceptions within the scale/position getters. Are there any restrictions on when you can use SetActive on entire panels or hierarchies containing panels?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I've never heard of or encountered an issue like that. The mTrans is set on awake, so there is no reason for it to ever be null.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Are you sure you aren't pausing the game while its running, recompiling some script, then tabbing back to Unity? That would indeed cause this kind of stuff, but that's just how Unity works.

getluky

  • Guest
Yes, I found it very odd as well. It's happened twice to me with checkboxes with TweenPosition/TweenScale components, and once with a standalone label with TweenPosition/TweenScale. My best guess was that I have some panels that are disabled on launch, and that on the first frame of being enabled they're getting their update method called before Awake has a chance to run. I tried to reproduce it in the example scenes but couldn't do so thus far. I will try to get a small test case when I have a chance, but so far the workaround is just to use Animation components instead.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I reproduced it this morning and submitted a bug about it to Unity. It turned out to be an issue I've seen before with Localization.

Adding an empty OnEnable function to the tween scripts fixes this btw.

It's just a Unity bug.
« Last Edit: April 20, 2012, 01:51:38 PM by ArenMook »

getluky

  • Guest
Thank you for tracking this down!