• Runtimes
  • When animation ends then do something in unity

Related Discussions
...

In unity how I can activate function when Spine animation ends?

Once event timeline is done you can use that. Until then you can use the AnimationState time or AnimationState isCompleted.

Is there a option to ask what animation is now playing?

example:

if(animationplayingname == "attack" && skeletonAnimation.state.Time <= 0) {
dosomething();
}

Or is there a better way to do this?

Thanks! 🙂

Edit: I found it! skeletonAnimation.state.Animation.Name

Thanks for help Nate and for fast answers! 🙂

Bingo! :clap:

As a sidebar, Nate:

For checking the current animation of an AnimationState, particularly in C#/Java;
What do you think of:
(a) using a string compare (by checking if AnimationState.Animation.Name == "animationname")

vs.

(b) using a reference compare (by checking if AnimationState.Animation == a cached Spine.Animation reference, probably preloaded at initialization with SkeletonData.FindAnimation("animationname") )
?

Really not a point of concern? Any design considerations?

A single string comparison is (generally) fine. Many string comparisons isn't so great. The reference comparison is obviously more efficient, but unless the difference actually affects the application user (and it most likely doesn't) then fretting over the difference is a misuse of your time. 🙂