【Unity】Getting Started with Unity Animator Controller: Mastering Animation State Control

Created: 2026-02-05

Learn how to manage character animations with Unity's Animator Controller. Covers State Machine, Transitions, Parameters, and Blend Trees in detail.

Overview

Tested with: Unity 2022.3 LTS / Unity 6

"I want to add multiple animations to a character..." "I want to smoothly transition from walking to jumping..."

These are common challenges when implementing animations for characters and objects in Unity. The Animator Controller is Unity's official animation management system. It lets you visually manage multiple animation clips and control transitions between them using a State Machine.

Creating an Animator Controller

Method 1: Create Manually

  1. Right-click in the Project window
  2. Select "Create" > "Animator Controller"
  3. Set the file name (e.g., "PlayerAnimator")

Method 2: Automatic Creation

When you animate a GameObject using the Animation Window, an Animator Controller is automatically created.

Assigning to a GameObject

  1. Select the GameObject
  2. In the Inspector, select "Add Component" > "Animator"
  3. Drag and drop the Animator Controller you created into the Controller field of the Animator component

About Apply Root Motion

The Animator component has an "Apply Root Motion" checkbox.

SettingBehavior
OnMovement and rotation from animations are applied to the character
OffAnimation movement and rotation are ignored; controlled by script

Tip for beginners: If you control character movement through scripts, set this to Off. Leaving it on can cause unintended behavior when both animation and script movement are applied simultaneously.

State Machine Basics

When you open the Animator Window, several default States are already in place.

StateDescription
EntryThe starting point for animation transitions
Any StateA special state that allows transitions to any state from any state
ExitReturns to the parent layer from a Sub-State Machine (in the root layer, transitions back to the default State via Entry)

About Exit behavior: Exit returns control to the parent State Machine when used inside a Sub-State Machine. In the root-level State Machine, transitioning to Exit loops back to the default State through Entry.

Creating a State

  1. Right-click on an empty area in the Animator Window
  2. Select "Create State" > "Empty"
  3. Assign an animation clip to the Motion field

Alternatively, you can drag and drop an animation clip from the Project window to automatically create a State.

Creating Transitions

  1. Right-click on the source State
  2. Select "Make Transition"
  3. Click on the destination State

Transition Settings

SettingDescription
Has Exit TimeOn: transitions after the animation finishes; Off: transitions immediately
Transition DurationDuration of the transition (smoothness of the blend)
ConditionsConditions that trigger the transition

Using Parameters

Parameters are used for communication between scripts and the Animator Controller.

Parameter Types

TypeUse Case
FloatFloating-point numbers (e.g., movement speed)
IntIntegers (e.g., ammo count)
BoolTrue/false values (e.g., whether the character is walking)
TriggerOne-shot flags (e.g., jump)

Creating Parameters

Click the "Parameters" tab on the left side of the Animator Window and add parameters using the "+" button.

Controlling the Animator from Script

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Animator animator;

    void Start()
    {
        animator = GetComponent<Animator>();
    }

    void Update()
    {
        // Get movement input
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        Vector3 movement = new Vector3(horizontal, 0, vertical);
        float speed = movement.magnitude;

        // Set the Animator parameter
        animator.SetFloat("Speed", speed);

        // Jump input
        if (Input.GetKeyDown(KeyCode.Space))
        {
            animator.SetTrigger("Jump");
        }
    }
}

Parameter Setting Methods

animator.SetBool("isWalking", true);
animator.SetFloat("Speed", 5.0f);
animator.SetInteger("AmmoCount", 10);
animator.SetTrigger("Jump");

Using Blend Trees

A Blend Tree smoothly blends multiple animations based on parameter values.

Creating a Blend Tree

  1. Right-click on an empty area in the Animator Window
  2. Select "Create State" > "From New Blend Tree"
  3. Double-click the Blend Tree to open the editing view
  4. Select the "Blend Type" (typically "1D")
  5. Choose a "Parameter" (e.g., "Speed")
  6. Add animation clips and set their Thresholds

Example:

  • Idle - Threshold: 0
  • Walk - Threshold: 0.5
  • Run - Threshold: 1.0

Using Animation Layers

Animation Layers allow you to overlay multiple State Machines.

For example, you can play a full-body walking animation while playing an attack animation on the upper body only.

Layer Settings

SettingDescription
WeightLayer weight (0 to 1)
BlendingOverride (replace) or Additive (add on top)
MaskWhich body parts the layer applies to (Avatar Mask)

Practical Examples

Example 1: Movement Animation (Blend Tree + Script)

using UnityEngine;

public class MovementAnimator : MonoBehaviour
{
    [SerializeField] private float walkSpeed = 2f;
    [SerializeField] private float runSpeed = 5f;

    private Animator animator;
    private CharacterController controller;

    // Hash parameter names for better performance
    private static readonly int SpeedHash = Animator.StringToHash("Speed");

    void Start()
    {
        animator = GetComponent<Animator>();
        controller = GetComponent<CharacterController>();
    }

    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        Vector3 move = new Vector3(h, 0, v);

        // Sprint check (Shift key)
        float targetSpeed = Input.GetKey(KeyCode.LeftShift) ? runSpeed : walkSpeed;

        // Normalize to match Blend Tree threshold (0 to 1)
        // move.magnitude can be sqrt(2) (~1.41) during diagonal movement, so clamp it
        float normalizedSpeed = Mathf.Clamp01(move.magnitude) * (targetSpeed / runSpeed);
        animator.SetFloat(SpeedHash, normalizedSpeed);

        // Movement
        controller.Move(move.normalized * targetSpeed * Time.deltaTime);
    }
}

Performance tip: Using Animator.StringToHash to hash parameter names avoids per-frame string comparisons. This is especially effective for frequently called methods like SetFloat and SetBool.

Example 2: Jump Animation

// Any State to Jump Transition settings:
// - Conditions: Jump (Trigger)
// - Has Exit Time: Off
// - Transition Duration: 0.1

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
    {
        animator.SetTrigger("Jump");
    }
}

Example 3: Attack Animation (Combo Support)

// Transition settings:
// - Idle to Attack: Conditions: Attack (Trigger), Has Exit Time: Off
// - Attack to Idle: Has Exit Time: On (auto-transition after attack animation finishes)

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        animator.SetTrigger("Attack");
    }
}

Animator Override Controller

The Animator Override Controller lets you reuse the structure (State Machine, Transitions) of an existing Animator Controller while swapping out animation clips.

Use Cases

  • Enemy variations (same behavior, different visuals)
  • Swapping attack motions per weapon type
  • Character skin variants

How to Create

  1. Right-click in the Project window > Create > Animator Override Controller
  2. Set the source Animator Controller in the "Controller" field
  3. Replace the animation clips shown in the list
// Dynamically swapping via script
public AnimatorOverrideController slimeOverride;
public AnimatorOverrideController goblinOverride;

void SetEnemyType(EnemyType type)
{
    animator.runtimeAnimatorController = type == EnemyType.Slime
        ? slimeOverride
        : goblinOverride;
}

Summary

The Animator Controller is Unity's official animation management system.

  • State Machine - Visually manage multiple animations
  • Parameters - Control animations from scripts
  • Transitions - Configure transitions between animations
  • Blend Tree - Smoothly blend multiple animations
  • Animation Layers - Overlay multiple animations

Use the Animator Controller to bring your characters to life with dynamic, responsive animations.

Further Learning