Unity Animator

What is an Animator Controller?

An Animator Controller in Unity is an asset that controls the flow of animations in a GameObject. Think of it as a visual state machine where you define how one animation transitions into another based on logic and parameters. This controller is assigned to the Animator component on a GameObject and becomes the core hub for animation logic.

Animator controller

Animator Controllers are most often used with characters, enemies, NPCs, UI elements, and anything else that needs a sequence of animations or reactions to inputs, triggers, or events.

Core Concepts of Animator Controllers

Animator Controllers are built around several key concepts:

1. States

States are the building blocks of an Animator Controller. Each state typically represents an Animation Clip. For example, you might have states like Idle, Walk, Run, Jump, Attack, etc.

States

When a GameObject is being animated, it will always be in one of these states. Unity plays the animation assigned to the current state until it's told to transition to another.

2. Transitions

Transitions

Transitions define how and when Unity moves from one state to another. You can specify:

Transitions allow you to control the flow of animations based on gameplay input or logic.

3. Parameters

Parameters are variables used to control transitions. These are defined inside the Animator Controller and can be of different types:

You update these parameters through script or animation events. For example, if your player presses the jump button, you could set IsJumping to true, which would trigger a transition from Idle or Run to the Jump animation.

4. Sub-State Machines

A Sub-State Machine is a container of states. It’s useful for organizing large Animator Controllers into modular sections. For example, you could have one sub-state machine for Locomotion (Idle, Walk, Run) and another for Combat (Attack, Block, Dodge). This keeps your Animator clean and manageable.

5. Any State

The Any State node is a special state that can transition into any other state, regardless of the current one. It's often used for animations that should be played immediately, such as a damage reaction or death animation.

Creating an Animator Controller in Unity

To create and set up an Animator Controller in Unity, follow these steps:

Step 1. Create the Animator Controller

Step 2. Assign it to a GameObject

Step 3. Open the Animator Window

Step 4. Add Animation States

Step 5. Define Parameters and Transitions

Controlling the Animator via Script

You control the Animator Controller’s behavior using Unity’s scripting API. The most commonly used component is Animator, which provides methods to set parameters and trigger transitions.

Here’s a basic example

public class PlayerMovement : MonoBehaviour
{
    public Animator animator;

    void Update()
    {
        float move = Input.GetAxis("Horizontal");
        animator.SetFloat("Speed", Mathf.Abs(move));

        if (Input.GetButtonDown("Jump"))
        {
            animator.SetTrigger("Jump");
        }
    }
}

In this example:

Best Practices for Using Animator Controllers

Common Use Cases

Here are some common scenarios where Animator Controllers shine:

1. Character Animation

2. Enemy AI

3. UI Animations

4. Environmental Effects

Conclusion

Animator Controllers are one of Unity’s most powerful features for managing animation logic. With their state machine structure, parameter-based transitions, and sub-state machines, they provide a highly flexible system to control how your GameObjects animate and respond to the world.

By mastering Animator Controllers, you'll be able to build dynamic characters, responsive interfaces, and immersive worlds. Whether you're a beginner or an experienced developer, understanding and leveraging this system is essential to crafting polished and professional-quality Unity games.