AnimatorStateInfo.fullPathHash returns 0

I’m trying to check if my player is currently moving.

I found this Unity - Scripting API: AnimatorStateInfo. Unfortunately it seems that “fullPathHash” returns always 0.

Here’s my code

    private AnimatorStateInfo stateInfo;

    public bool IsInLocomotion() {
        Debug.Log ("StateInfo is " + stateInfo.fullPathHash + " LocomotionId is " + m_LocomotionId);
        // stateInfo.fullPathHash returns 0

        return stateInfo.fullPathHash == m_LocomotionId;
    }

I know I was able to get the hash at some point before in an older version of Unity by using AnimatorStateInfo.nameHash, but that method is now obsolete.
I think there’s something I might be doing wrong because even if it wasn’t what I was looking for it should definitely be returning at least something different from 0.

What am I doing wrong?

Apparently that is not enough, you also need to ask the animator to get the current animator state info with

stateInfo = animator.GetCurrentAnimatorStateInfo(0);

where “0” is the index of the layers in the animator