Mecanim: 2-step transitions in a single update (skip intermediate state)
I am trying to apply the spoke-hub pattern for a 2D platformer game to make my animations more manageable. But from what I understand, Unity will make only 1 transition per Update. This means that it can not transition directly from one of the leaf nodes in the hub-spoke graph to another leaf node without spending 1 stand-by frame in the intermediate hub / empty state.
In my case the state machine looks like this State machine. All my transitions are instant (HasExitTime=False, TransitionDuration=0). I want to transition from "JUMPING" to "RUNNING", therefore I set:
animator.SetBool("isRunning", True);
animator.SetBool("isJumping", False);
And I do end up in the running state, no problems there. But the transition does not happen in a single frame. It first transitions from JUMPING to IDLE in the 1st frame. and then it transitions from IDLE to JUMPING in the 2nd frame. This means that 1 frame is spent in the IDLE state during landing, which can be quite problematic in general if it happens everywhere in my state machine.
Is there any way to force the state machine re-evaluate itself in the 1st frame and see that it must go directly to "RUNNING" without wasting 1 frame in-between? Would the order that I set the parameters in the above code matter?
Edit: I found out you can force unity to re-evaluate the machine's state and jump to the next state by calling Animator.Update with a 0 deltaTime:
animator.SetBool("isRunning", True);
animator.SetBool("isJumping", False);
animator.Update(0);
If you want to jumpt 3 states, then you probably need to call Update 2 times.
Your answer
![](https://koobas.hobune.stream/wayback/20220613025155im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mecanim transition not smooth 0 Answers
Prevent Colliders animating between animation states or transition the colliders instantly 0 Answers
In my StateMachineBehaviours public variables do not update in the inspector 0 Answers
Can I copy moves from one animator to another using Mecanim? 0 Answers
Animation won't transition from Idle 0 Answers