CodeBlanks Logo Icon CodeBlanks

State machine

Learn states and transitions in an Animator Controller.

State Machine States

Each State inside an Animator Controller represents a specific animation state. For example, a character's hurt, death, or attack animations can be defined as separate states. An Animation Clip can be assigned to each state.

// Hurt
// Death
// Attack

Understanding Transition Duration and Conditions

Transition settings determine how the change from one state to another occurs. When Has Exit Time is enabled, a transition can occur when the current animation reaches its exit time. Transition Duration controls the blending time between two animations.

// Has Exit Time
// Transition Duration
// Conditions

Practice Check the Transition Status

Check whether a transition is active on layer 0 of the Animator component. If a transition is in progress, print Transition in progress; otherwise, print No transition.

Starter code

Player.cs
using UnityEngine;

public class TransitionCheck : MonoBehaviour
{
    public Animator animator;

    void Update()
    {
        
    }
}

Sample solution

Player.cs
using UnityEngine;

public class TransitionCheck : MonoBehaviour
{
    public Animator animator;

    void Update()
    {
        bool transitioning = animator.IsInTransition(0);

        if (transitioning)
        {
            Debug.Log("Geçiş devam ediyor");
        }
        else
        {
            Debug.Log("Geçiş yok");
        }
    }
}

Expected output

Geçiş yok

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where does the animation data played by a State in an Animator Controller usually come from?

  • Mesh Collider
  • Material
  • Animation Clip Correct answer
  • Audio Source

Explanation: An Animation Clip is assigned to a State to define the animation it plays.

2 Identify the Transition Duration

Question
İki animasyon arasındaki karışımın ne kadar süreceğini belirleyen Transition ayarı ____ olarak adlandırılır.
Answer
İki animasyon arasındaki karışımın ne kadar süreceğini belirleyen Transition ayarı Transition Duration olarak adlandırılır.

Explanation: Transition Duration determines the blending time between animations.

3 Match Transition Settings

Term Meaning
Has Exit Time Considers current animation exit time
Transition Duration Blend duration between two animations
Condition Requirement for a transition to occur
Destination State Target state reached by transition

All lessons in Intermediate