Hello Guest

Author Topic: Problem with tk2dSpriteAnimator.CurrentClip  (Read 4009 times)

Cybertiger

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Problem with tk2dSpriteAnimator.CurrentClip
« on: November 14, 2013, 03:12:32 pm »
Hello,

I am trying to recieve the currentClip name but i have problems doing so:

Code: [Select]
public static void playClip(tk2dSpriteAnimator animator, string clipName)
{
//check if the clip exists
if(animator.GetClipByName(clipName) != null)
{

//THIS PART RAISES ERROR: Object no set to an instance of an object
print (animator.CurrentClip.name);

print ("AnimHelper: Now playing clip " + clipName);

animator.Play(clipName);
} else
{
print ("AnimHelper: ATTENTION.... clip " + clipName + " does not exist for GameObject " + animator.gameObject.name);
}

}

But if i comment out the line with "CurrentClip" i don't get the error: "Object not set to an instance of an Object"
Thanks for your help

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with tk2dSpriteAnimator.CurrentClip
« Reply #1 on: November 14, 2013, 03:19:58 pm »
CurrentClip is only assigned when you Play, it implies your animator doesn't have a current clip set at that point.

tk2dSpriteAnimationClip clip = animator.GetClipByName(name);
if (clip != null) {
   animator.Play(clip);     
}

or check for animator.CurrentClip for null before using it.