- Home /
How can I tell what AnimationState mecanim Animator is in from script?
I'd like to do some specific code-side stuff when my Animator enters certain states, but I can't figure out how to tell what state it's in from script. For example, I have an AnimationState called "Ambulate" - it looks like I should be able to do something like -
AnimatorStateInfo asi = myAnim.GetCurrentAnimatorStateInfo(0);
int ambulateHash = Animator.StringToHash( "Ambulate" ); // or asi.IsName("Ambulate")
if( asi.nameHash == ambulateHash )
{
// ... do my special stuff ...
}
But neither of those work. Any help?
Answer by JamieFristrom · Jan 08, 2013 at 11:06 PM
Ah. It's actually "Base Layer.Ambulate" - and don't forget the space in Base Layer. Wouldn't you know I'd figure it out right after posting the question.
Your answer
![](https://koobas.hobune.stream/wayback/20220613090623im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Accessing AnimationState in Animator 0 Answers
Get the clip length (accounting for speed multipliers) of any animation state at runtime 1 Answer
Why does this animator appear to occupy two states, but report only one? 0 Answers
Get an Animator state inside an AnimationEvent callback of the last frame 2 Answers
accessing animation states from animator in javascript 0 Answers