- Home /
How to check if a specific animation is playing within mecanim
Hi there,
with the old legacy system I know that you can use: Animation.IsPlaying("animName") to return a bool value as to whether or not the specified animation is playing.
Does this same thing exist for mecanim within an Animator?
Specifically I want to do the equivalent of:
if(Blendtree named "Running" is playing) { //Do action }
Can anyone help with this?
Answer by darthbator · Oct 22, 2013 at 01:35 AM
It's a little different then it was before (stuff like blend states can really complicate "what is now playing"). You'll want to use this function to get the aimator state info. From there you can call the isName() function or check against the "nameHash" from the animatorStateInfo object returned to you and evaluate your logic against that.
nameHash doesn't return the actual name of the animation, and isName returns a boolean value. I get your point but cannot figure out how to join all those things together to do something.
O$$anonymous$$, let it be. I found some functional code here:
http://answers.unity3d.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html
Answer by tyoc213 · Oct 28, 2014 at 06:13 PM
Animator some = gameObject.GetComponentInChildren<Animator> ();
AnimationInfo[] ainfo = some.GetCurrentAnimationClipState(0);
if(ainfo.Length == 0){
/*** no animation running***/
}else{
for(int idx=0;idx<ainfo.Length;idx++){
}
}
Your answer
Follow this Question
Related Questions
How to check if an object is playing ANY animation 1 Answer
mecanim animation runs at random speed on iOS 0 Answers
Mecanim and Ragdoll Issues? 2 Answers
Mecanim animation not working correctly after separating from original fbx 0 Answers
Ensure Mecanim registers Boolean before turning off? 2 Answers