Setup
Attached to ‘New StateMachine’ is the following class
public class TestState : StateMachineBehaviour
{
[SerializeField]
private string m_Tag = "Default";
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log ("OnStateEnter >> " + m_Tag);
}
public sealed override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log ("OnStateExit >> " + m_Tag);
}
}
‘New StateMachine’ is a sub-state Machine as follows:
When the substate machine transitions from ‘New State’ to ‘New State0’ to ‘New State 1’, the OnStateEnter/OnStateExit of attached to the parent state machine get called.
Intuitively, one would assume that the OnStateEnter/OnStateExit do not get called when transitioning between substates of a sub-state machine.
I’m just curious if any one knows of the justification for this design decision. and if there is a way to get the behaviour I’m looking for:
When attaching a StateMachineBehavior to a parent state machine, the OnStateExit/OnStateEnter do not get triggered when the sub-states of the state machine are transitions. These methods only get triggered when the parent state transitions.
As a workaround, I guess I could do name compares in the OnStateEnter/OnStateExit but that seems a bit clunky. not sure if this is the ideal solution though. It seems like others would have solved this issue as it feels like a common use case to me.
Thanks for any help/insight.