1
\$\begingroup\$

Question

Why doesn't an animation transition with an Exit Time of 0 immediately transition to the next state?


Minimal example

Using Unity 2018.3, I set up an AnimatorController with two states: Initial and Next. I wanted Initial to transition to Next immediately, so I tried setting an Exit Time of 0. However, this doesn't transition immediately:

ExitTimeZeroResult

As shown above, Initial state still runs instead of transitioning immediately to the Next state. (There is no Motion attached to the AnimationState, so perhaps it's using a default duration.)

Below are screenshots of my animation transition settings.

Initial-to-Next Next-to-Initial


Strange behaviour with small non-zero ExitTime

I also tried using an Exit Time of 0.01 (i.e. transition after 1% of the animation has played), and it transitions almost immediately as I expect most of the time. However, occasionally it will still play the Initial state:

ExitTime-0.01 Initial-To-Next-For-ExitTime-0.01

In this case, even though it transitions to Next immediately most of the time, it still occasionally waits for the Initial state to complete. (It happens much less frequently than the image above suggests, but the issue becomes more frequent if I set the ExitTime even lower, e.g. 0.003).


Workaround

From searching online, the recommended solution for immediate animation transitions seems to be to turn off Exit Time and use a condition (e.g. bool or trigger) to transition immediately instead.

(Edit: in my case, I've defined an animator bool parameter called ImmediateTransition and set it to true by default instead of using Exit Time 0.)

This seems to work, but I would like to better understand how Exit Time works and why it's not working the way I expect.

\$\endgroup\$
2
\$\begingroup\$

Has Exit Time: Exit Time is a special transition that doesn’t rely on a parameter. Instead, it relies on the normalized time of the state. Check to make the transition happen at the specific time specified in Exit Time.

Exit Time: If Has Exit Time is checked, this value represents the exact time at which the transition can take effect. This is represented in normalized time (for example, an exit time of 0.75 means that on the first frame where 75% of the animation has played, the Exit Time condition is true). On the next frame, the condition is false.

Fixed Duration: If the Fixed Duration box is checked, the transition time is interpreted in seconds. If the Fixed Duration box is not checked, the transition time is interpreted as a fraction of the normalized time of the source state.

Transition Duration: The duration of the transition, in normalized time or seconds depending on the Fixed Duration mode, relative to the current state’s duration. This is visualized in the transition graph as the portion between the two blue markers.

enter image description here

Transition Offset: The offset of the time to begin playing in the destination state which is transitioned to. For example, a value of 0.5 means the target state begins playing at 50% of the way through its own timeline.

Interruption Source: Use this to control the circumstances under which this transition may be interrupted.

Ordered Interruption: Determines whether the current transition can be interrupted by other transitions independently of their order.

Conditions: A transition can have a single condition, multiple conditions, or no conditions at all. If your transition has no conditions, the Unity Editor only considers the Exit Time, and the transition occurs when the exit time is reached. If your transition has one or more conditions, the conditions must all be met before the transition is triggered.

A condition consists of:

  • An event parameter (the value considered in the condition).
  • A conditional predicate (if needed,for example, ‘less than’ or ‘greater than’ for floats).
  • A parameter value (if needed).

If you have Has Exit Time selected for the transition and have one or more conditions, note that the Unity Editor considers whether the conditions are true after the Exit Time. This allows you to ensure that your transition occurs during a certain portion of the animation.

For more information please visit: Unity Manuel.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the details, but I still don't understand why an exit time of 0 doesn't cause an immediate transition. According to the definition here, shouldn't a 0 exit time mean that on the first frame where 0% of the animation has played, the Exit Time condition should be true? \$\endgroup\$ – sonny Aug 28 at 15:01
  • \$\begingroup\$ Ok. "Exit time" is not the only property which cause the transition but there is impact of the "transition duration" and "fixed duration". i can see you have setup the "transition duration" to 0 which is good also disable the "fixed duration" check box and set "exit time" to 0 and unchecked the "has exit time". please let me know if it worked, because i kinda curious know. hehehe \$\endgroup\$ – Swati Aug 29 at 4:27
  • \$\begingroup\$ Yes, unchecking "Has Exit Time" and using a condition instead will work. I mentioned this already in my question in the "Workaround" section. \$\endgroup\$ – sonny Aug 29 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.