GetNextAnimatorStateInfo().taghash is always 0
Hi folks.
I'm using Mecanim to handle my combo system.
The idea is pretty simple, every state that belongs to the same combo is labelled with the same tag.
All attack states are in the same submachine.
To know if the combo is still going or has been interrupted I want to check the next state tag, so I wrote this on a StateMachineBehaviour.
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log(animator.GetNextAnimatorStateInfo(0).tagHash);
Debug.Log(stateInfo.tagHash);
if (animator.GetNextAnimatorStateInfo(0).tagHash!=stateInfo.tagHash)
{
Debug.Log("Esco dalla combo");
CharacterInput.attacking = false;
}
}
As expected, the second Debug.Log writes the same hash for every combo state I'm currently into, but the first one always writes 0.
Am I doing something stupid up there? Since the documentation states that GetNextAnimatorStateInfo is only available on transitions and OnStateExit is called on the last frame of a transition from the behaviour carrier, this should be perfectly legit!
Thank you in advance for your time
Answer by IgorAherne · May 11, 2018 at 12:19 AM
For next sufferers, OnStateExit occurs at the end of the transition. Your destination state has already invoked OnStateEnter some time earlier.
Because your transition is already ended, the Next state is actually already treated as "the Current" state.
So instead, use animator.GetCurrentAnimatorStateInfo()
Thank you! This was exactly my problem and that worked a charm.