Hello Guest

Author Topic: Inexplicable NullReferenceException when getting ClipTimeSeconds  (Read 3208 times)

ItsMeAlan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
This code:
Code: [Select]
if (genIcon.ClipTimeSeconds != 0)
{
genIcon.Resume();
}

is causing this error:

Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
tk2dAnimatedSprite.get_ClipTimeSeconds () (at Assets/Plugins/tk2d/Sprites/tk2dAnimatedSprite.cs:198)
touchControls.Update () (at Assets/Scripts/touchControls.js:315)

I am pretty confident that genIcon is indeed pointing to a valid td2kAnimatedSprite object. The script appears to be working exactly like I want it to, but it's firing off this error once per frame, clogging up my console. Anyone have any ideas why?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Inexplicable NullReferenceException when getting ClipTimeSeconds
« Reply #1 on: April 01, 2013, 01:30:28 pm »
That callstack looks very much like genIcon is null, or currentClip is null. Current clip can only be null if nothing has ever been played on that animated sprite.
Add some debug code around it to make sure, or run it through the debugger to see what is null..