- Home /
How to get Animator's Layer --> Sub-State --> State namehash?
I'm using the following structure:
(Layer) "Base Layer" --> (Sub-State) "Jump_Fall_Roll" --> (State) "Roll"
static int rollState = Animator.StringToHash("What to put here??");
private Animator anim;
private AnimatorStateInfo currentBaseState;
void Start ()
{
anim = GetComponent<Animator>();
}
void FixedUpdate ()
{
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
if (currentBaseState.nameHash == rollState) {
Debug.Log ("ROLL nameHash worked"); //Not working
}
if (currentBaseState.IsName("Roll")) {
Debug.Log ("ROLL IsName worked"); //Working.......
}
}
I tryed every possible combinaison of parents/states for the nameHash, but it never worked...
The name should be in the form Layer.Name, for example "Base.Idle".
AnimatorStateInfo.IsName doc from Unity
So, why is my first case not working? And how can the second case work??
I'm really confused.
Thank you!
I'm having this exact same problem - did you ever find a solution?
Yes, I made this Stackoverflow post too : http://stackoverflow.com/questions/22956518/unity3d-how-to-get-animators-layer-sub-state-state-namehash/22972594#22972594 Thank you :)
Answer by deram_scholzara · Dec 17, 2014 at 12:20 AM
So, I found the answer here: http://answers.unity3d.com/questions/826835/problem-with-hash-ids-end-of-animation-detection.html
Apparently Unity just hasn't documented getting hashes for States in SubStates.
What you have to do is replace the layer portion with your SubState node name. In your case, this would end up being "Jump_Fall_Roll.Roll". You just leave out the "Base Layer" part completely.
Answer by sergiusz308 · Nov 30, 2020 at 12:44 AM
In 2020 things are little bit different though.
To get substate full-hash you need to provide:
(layer name).(sub state name).(state name within sub state)
For example, considering you have "Base Layer" and then "jumping" substate and inside you have "jumping loop" state. Your path would be:
"base layer"."jumpin"."jumpin loop"
S.
Your answer
Follow this Question
Related Questions
Animation From blender to Unity Animator - Import Error 1 Answer
Namehash BLENDTREE in Substate 0 Answers
Cloud recognition in Vuforia 0 Answers
How to controll parameters in animator using javascript 1 Answer
UnityEngine.AnimatorStateInfo.nameHash' is obsolete: "Use AnimatorStateInfo.fullPathHash instead." 0 Answers