The AnimatorStateInfo is the current info for the state that the state machine behaviour is on. It is the equivalent of writing animator.GetCurrentStateInfo(layerIndex); This can be useful in operations that involve the normalised time of the clip.
I’ve noticed that this isn’t always true. In my project, the following code prints the debug message up to 12 frames in a row:
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (animator.GetCurrentAnimatorStateInfo(layerIndex).shortNameHash != stateInfo.shortNameHash)
Debug.Log("Inconsistent AnimatorStateInfos...");
}
Unfortunately, this is in a project from which I’m not currently able to file bug reports. But it seems to me that this is a small bug that should be easy to find and fix.
After further investigation this is expected, you cannot use animator.GetCurrentAnimatorStateInfo like this. Here the reason
Let say you have a controller with 2 State A and B with a transition from A to B and you have a StateMachineBehaviour (SMB) on state B only. When your SMB will start to get is first callback OnStateEnter, it does mean that the StateMachine is doing a transition between A to B, so in this case B is the next state, to correctly validate that both AnimatorStateInfo are equivalent you should use animator.GetNextAnimatorStateInfo.
This is exactly why we did add AnimatorStateInfo as a parameter to all callback. Remove some complexity to handle such case.