- Home /
Does it always require 1 frame per state to transition between several animator states?
I'm trying to create a 2D sprite animation using the Animator, and I ran into a problem. Using the image below as reference, I have 3 different toggles:
Toggle 1 transitions StateIdle to State 1
Toggle 2 transitions State1 to State 2
Toggle 3 transitions State2 to State 3
Sometimes all three toggles become active at once, and ideally I would like State 3 to begin playing immediately, but in this case 1 frame plays from both State 1 and State 2 before finally transitioning to State 3, which creates a noticeable sprite flicker.
The transition durations are set to 0, and atomic is turned off, so I'm guessing this is just the way Mecanim handles transitions (i.e. only one state and transition is checked per update)? This doesn't seem ideal, since you should be able to transition between several states during a single update.
Is there any way to not show a single frame from each state and to jump straight to State 3 using this layout? Or will I have to create a separate toggle and transition if I want to jump from StateIdle straight to State 3 without showing frames from State 1 and State 2?
Bump.
Is this any different in Unity 5? Seems like a valuable feature.. especially considering the fact that we have State$$anonymous$$achineBehaviors now and we can use the state machines to handle logic... I don't see any reason that I shouldn't be able to flow through multiple states in a single frame, all handing different logic.
Answer by Bunny83 · Oct 19, 2015 at 04:12 PM
Well, a state machine always follows a deterministic flow. Unity seems to only allow one transition per frame. If you want to go straight from state 1 to state 3 you should have another transition that represents that. You don't need a new variable, just setup your transition conditions accordingly.
If multiple transitions per frame where allowed it would be quite easy to create an infinite loop when switching between two states within the same frame. This would result in a freeze.
A StateMachineBehaviour has several callbacks where some can only be called when an actual frame has happened. (Specifically: OnStateIK, OnStateMove, OnStateUpdate). Also transitions between multiple statemachines would be problematic as well since the order in which they are processed would depend on the current transition chain.
Your answer
Follow this Question
Related Questions
How to stop mesh disappearing during Animator state transition blend time? 1 Answer
Mecanim smooth transition from arbitrary time in animation 1 Answer
Mecanim transition retargeting and conditional exit to any state? 0 Answers
is it possible to read states / transitions from mecanim in runtime ? 2 Answers