StateMachineBehaviour: OnStateEnter/OnStateExit called multiple times using substates

Setup

9441536--1324556--upload_2023-10-30_23-8-33.png

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:
9441536--1324559--upload_2023-10-30_23-10-16.png

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.

9441536--1324562--upload_2023-10-30_23-11-23.png

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.

And this post from:

seems like a bit of a clunky solution

same problem:(