Course contentsShow
← Unity Game Development
Lesson 369 of 8286. Animation and CinemachineFree lesson

Designing Animator Controller State Machines

You will construct a visual state machine to define the logical flow between different character animation clips.

Designing Animator Controller State Machines

In this lesson, you will learn how to visually map out your character’s behavior using Unity’s Animator Controller window to transition between different animation clips based on game logic.

Think of an Animator Controller as a flowchart for your character’s movement. Each box in the graph represents a State—an animation clip like "Idle," "Walk," or "Jump"—and the arrows connecting them are Transitions. These transitions are the rules that tell Unity when to stop playing one animation and start another.

Building the Logic Flow

To create this flow, you first drag your animation clips into the Animator window. Unity automatically creates a default state (usually orange), which is the first animation to play when the object spawns.

To connect states, you right-click a state and select Make Transition, then click on your target state. However, a transition won't fire unless you define a Parameter. Parameters are variables—like a bool for isGrounded or a float for speed—that bridge the gap between your C# code and the animation system.

For example, if you want your character to switch from "Idle" to "Walk," you would:

  1. Create a float parameter called Speed.
  2. Select the transition arrow.
  3. In the Conditions section of the Inspector, add Speed > 0.1.
  4. In your C# script, update that value using animator.SetFloat("Speed", movementValue);.

Managing Transitions

As you build these links, pay attention to the Settings dropdown on your transition. Here, you can define Has Exit Time, which determines if an animation must finish playing before moving to the next. For snappy movement like running, you typically want to uncheck this so the state switch happens immediately when the player moves the joystick.

By keeping your state machine organized and using parameters as the "logic gate" for transitions, you ensure your character reacts smoothly to player input without stuttering or skipping frames.

Key Takeaway: An Animator Controller uses visual states and parameter-driven transitions to dictate exactly when your character switches between animation clips based on real-time game conditions.