2D Toolkit Forum

2D Toolkit => Support => Topic started by: Cybertiger on November 14, 2013, 03:12:32 pm

Title: Problem with tk2dSpriteAnimator.CurrentClip
Post by: Cybertiger 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
Title: Re: Problem with tk2dSpriteAnimator.CurrentClip
Post by: unikronsoftware 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.