CHAPTER 09
Beginner
Animations and Animator Controller
Updated: May 16, 2026
30 min read
# CHAPTER 9
Animations and Animator Controller
1. Introduction
A static 3D model sliding across the floor breaks immersion immediately. To bring a character to life, their legs must pump when they run, they must recoil when hit, and they must swing their sword when attacking. Unity provides a robust, visual node-based system to manage these complex movements called the Animator Controller. In this chapter, we will master the Unity Animation system. We will explore how to import animations, build a State Machine, set up conditional Transitions, and seamlessly blend walking and running loops using Blend Trees.2. Learning Objectives
By the end of this chapter, you will be able to:- Understand the difference between an Animation Clip and an Animator Controller.
- Build a visual State Machine in the Animator Window.
- Create Transitions between animations using Parameters (Booleans, Triggers).
- Trigger animations from C# scripts.
- Use a Blend Tree to smoothly mix idle, walk, and run animations.
3. Clips vs. Controllers
-
Animation Clip (
.anim): A single, specific movement. (e.g., "Jump", "Run", "Die"). Usually created in Blender/Maya and imported into Unity.
- Animator Controller: The "Brain". A visual flowchart that tells Unity *when* to play which Animation Clip. (e.g., "If speed > 0, play Run. If speed == 0, play Idle").
4. The Animator Window (State Machine)
- 1. Select your 3D character (it must have an Animator component).
- 2. Go to Window -> Animation -> Animator.
- 3. This opens a node-graph window. You will see an "Entry" state.
- 4. Drag an Animation Clip (like "Idle") from your Project window into the Animator. It becomes a rectangular Node.
- 5. The default arrow from "Entry" connects to "Idle". When the game starts, the character will immediately breathe idly!
5. Animation Parameters and Transitions
How do we switch from Idle to Run?- 1. In the Animator Window, look at the top left and click the Parameters tab.
-
2.
Click the
+button and add a Bool (True/False) namedisRunning.
- 3. Right-click the "Idle" node -> Make Transition, and drag the arrow to the "Run" node.
- 4. Click the white transition arrow. In the Inspector, look at the "Conditions" list.
-
5.
Add a condition:
isRunning == true.
- 6. (Important): Uncheck Has Exit Time. If left checked, the character will refuse to run until the Idle animation finishes its current loop, causing the controls to feel unresponsive. Unchecking it forces an instant, smooth blend.
6. Controlling Animations via C#
To make the animation actually happen during gameplay, your movement script must talk to the Animator component and change thatisRunning parameter!
csharp
7. Blend Trees (Advanced Smoothness)
If your game supports analog controllers, the player might push the stick halfway. They shouldn't play the full "Sprint" animation, they should play a "Jog".-
A Blend Tree takes a
Speedfloat parameter (0.0 to 1.0).
- If speed is 0.0, it plays Idle.
- If speed is 0.5, it mathematically blends 50% Idle and 50% Run, resulting in a smooth Jog!
- If speed is 1.0, it plays full Run.
8. Visual Learning: The Animator Flowchart
txt
9. Best Practices
-
Mixamo: If you are a solo developer and cannot animate 3D characters yourself, use Adobe Mixamo (
mixamo.com). It is a massive, free library of thousands of high-quality, motion-captured animations (running, shooting, dancing) that import perfectly into Unity.
10. Common Mistakes
- Root Motion Chaos: Have you ever triggered a walking animation, and the character visually walks forward, but when the animation ends, they snap instantly back to where they started? This is a "Root Motion" issue. By default, animations should move in-place, and your C# Rigidbody code moves the physical capsule. Ensure "Apply Root Motion" is unchecked on the Animator component unless you specifically want the animation file to drive the physical transform.
11. Mini Project: Setup an Idle-Run State Machine
Objective: Create a character that idles and runs based on key presses.- 1. Download a free character with Idle and Run animations from the Unity Asset Store.
-
2.
Drag the character into the scene. Make sure it has an
Animatorcomponent.
- 3. Right-click in the Project window -> Create -> Animator Controller. Name it "PlayerAnim".
- 4. Drag "PlayerAnim" into the Controller slot on the character's Animator component.
-
5.
Open the Animator window. Drag the
IdleandRunanimation clips into the window.
-
6.
Create a Bool parameter named
isMoving.
-
7.
Make a transition from Idle to Run (Condition:
isMoving = true, Has Exit Time: False).
-
8.
Make a transition from Run back to Idle (Condition:
isMoving = false, Has Exit Time: False).
-
9.
Write a small C# script to set the bool to true when
Input.GetKey(KeyCode.W)is pressed. Watch your character come to life!
12. Practice Exercises
- 1. What is the difference between an Animation Clip and an Animator Controller?
- 2. If you want a punch animation to interrupt an idle animation instantly, which checkbox on the Transition Arrow must you disable?
13. MCQs with Answers
Question 1
You want an animation (like a Death sequence or a Sword Swing) to play exactly once and then stop, rather than being toggled on and off. Which Animator Parameter type should you use?
Question 2
What advanced Animator feature allows you to perfectly, mathematically blend a slow-walk animation with a fast-run animation based on how far the player is pushing an analog thumbstick?
14. Interview Questions
- Q: Explain the architecture of the Unity Animator Controller. How do States, Transitions, and Parameters interact to form a State Machine?
- Q: A character's jump animation feels sluggish and unresponsive to the player's input, waiting a half-second before actually playing. What specific Transition setting is causing this, and why?
- Q: Contrast "In-Place" animation combined with Rigidbody movement versus "Root Motion" animation. When would a developer intentionally use Root Motion?
15. FAQs
Q: Can I trigger a C# script FROM an animation? A: Yes! This is called an Animation Event. You can open the Animation timeline, place a marker exactly on the frame where the sword hits the ground, and tell Unity to run a C# function calledPlayClankSound() on that exact frame.