Can't get the current animation state name (hash or .IsName) to work.

I have some hard times trying to get the current animation state name in Unity, to perform specific actions while I’m in a certain state.
I want to know when I’m the “ThoughtsStill” state, I only have the default layer (Base Layer):

To do this, here is what I tried:

AnimatorStateInfo curr_state = _animator.GetCurrentAnimatorStateInfo(0);
if (curr_state.shortNameHash == Animator.StringToHash("ThoughtsStill"))
{
    Debug.Log("I'm in ThoughtsStill state").
}

which is not working.

I also tried with IsName() method but it is not working too (both tried to compare “Base Layer.ThoughtsStill” and “ThoughtsStill”).

I’m certain that I’m going in this ThoughtsStill state but I don’t know why I can’t get it.

Do you guys have any ideas or leads?

Thanks !

1 Like

Still can’t find any solutions, does someone know something about this?

1 Like

What is not working exactly? The comparison? Getting the StateInfo?

Having the same issue, cant believe this is still a thing lol. Someone from the Unity team need to make this more usable.

Still here Unity 2021.3.23f1

I’m not sure what the problem is.
I haven’t touched Animator in years, but after glancing the docs it’s obvious that this should work like this

var state = _animator.GetCurrentAnimatorStateInfo(0);
if(state.IsName("Base.ThoughtsStill")) {
  Debug.Log("I'm in ThoughtsStill state");
}

I mean just read what is written.
I am not referring to the OP btw, but OP is the only one who at least bothered with an example.

Referring to the OP example :

curr_state.shortNameHash == Animator.StringToHash("ThoughtsStill")

should be indeed equal.

When using _animator.HasState(0, Animator.StringToHash("ThoughtsStill")) it will return true, so shortNameHash doesn’t refer to ThoughtsStill nor fullPathName to Base Layer.ThoughtsStill

OP :

your test was successful?

Can’t you appreciate the difference between the following strings

“ThoughtsStill” [OG]
“Base Layer.ThoughtsStill” [OP’s version]
“Base.ThoughtsStill” [what should’ve been]

?

It wasn’t because OP tried “Base Layer.ThoughtsStill”.

Besides, this thread is 5 years old, I doubt you’ll get a reply from OP.