Animator dont transition to self or any sub state


Here is a picture to explain what I want to achieve:

As you can see, AnyState transitions to JumpAndFall when isGrounded is false, and has can transition to self disabled. The problem is that when the state transitions to wallJump or doubleJump from JumpAndFall, then if isGrounded is true, since the current state is not JumpAndFall, it will transition to the state and then to wallJump or doubleJump again depending on which condition is true. So basically I want to stop AnyState from transitioning to JumpAndFall again as long as the current state is JumpAndFall or any of the “child” states (i.e. states that can only be transitioned from JumpAndFall), in this picture this means as long as the current state is one of the 3 states in the red circle, then don’t do the transition from AnyState.

Is there any way to do this? Thanks

Ok I found how to do this: I created a new bool variable called inAirState in the animator controller, then created a state machine behavior that I put on all 3 states JumpAndFall, doubleJump and wallJump. In the smb script, I set the inAirState bool to true on state enter, and set it back to false on state exit. Finally, the condition to go from AnyState to JumpAndFall now also has inAirState = false, thus while the current state is any of the 3 states in the red circle (above picture), the inAirState bool will have been set to true, otherwise it’ll be false.
This works but I really feel like it’s not a great solution, I thought there could be way to organize my hierarchy maybe with a sub state machine somehow to achieve this but I don’t know how.
For now I won’t mark this as the answer in case somebody comes up with a better way, if nobody replies I’ll just put this as the accepted answer.

How about:

  • making the transition from your Anim state (I assume this is the state when you character is on the ground) to JumpAndFall when isGrounded is false
  • making a transition from Any state to Anim when isGrounded is true or make 3 transitions (from each of your jump states) to Anim when isGrounded is true

Therefore when isGrounded becomes false the animator will be stuck in your red circle, until isGrounded it true again where you come back to your initial state.