🎬 Animation Lab
A self-directed sandbox for Unity's animation system. Three hands-on exercises, then dive into Mecanim — Unity's visual state machine for production-quality animation.
What You'll Do This Week
Two hours of focused practice. Hour 17 is sandbox-style — three short exercises to get fluent with the Animation window. Hour 18 moves up a level to Mecanim, Unity's state-machine-based animation system used in every shipped Unity game.
| Hour | Activity | Skill Built |
|---|---|---|
| 17 | Make a cube fly around in a large arc | Position keyframes, animation curves |
| 17 | Make a sphere flicker (renderer on/off) | Animating boolean component properties |
| 17 | Morph an object via scale and material change | Animating multiple properties at once |
| 18 | Build an Animator Controller for a door | States, transitions, parameters |
This week is about experimentation. Try things, break them, fix them. There are no marks for a polished result — only for understanding what each control does. Skim the official Unity docs at the end while concepts are fresh: docs.unity3d.com/Manual/AnimationSection.html
Project Setup
-
1Open Unity Hub → New Project → 3D (Core). Name it AnimationLab. Click Create.
-
2In the Project window, create folders:
Assets/Animations,Assets/Scripts,Assets/Materials. -
3Save the open scene as SandboxScene in
Assets/Scenes/. -
4Add a Plane at origin (GameObject → 3D Object → Plane) so animated objects have a visible ground reference.
Animation Fundamentals — 5 Things to Know
1. Two Different Windows
| Window | Open via | Purpose |
|---|---|---|
| Animation | Window → Animation → Animation | Edit a single clip — set keyframes, curves, properties |
| Animator | Window → Animation → Animator | Edit the state machine — connect clips, parameters, transitions |
These are two different windows that look similar. Animation = clip editor. Animator = state machine editor. Get them mixed up and you will waste 20 minutes wondering why nothing happens.
2. The Auto-Setup Magic
When you click Create in the Animation window for a GameObject with no animations, Unity creates 3 things at once:
3. Record Mode = Auto-Keyframing
The big red ● button in the Animation window. While Record is on, every property change to your GameObject gets saved as a keyframe at the current playhead position.
4. Two View Modes
Dopesheet (default)
- Compact timeline view
- Keyframes shown as diamonds
- Best for editing many properties
Curves
- Each property as a curve graph
- Drag tangent handles to ease in/out
- Best for fine-tuning motion feel
Switch between them with the tabs at the bottom-left of the Animation window.
5. Essential Shortcuts
| Shortcut | Action |
|---|---|
| Ctrl/Cmd + 6 | Toggle Animation window |
| K | Add a keyframe at current time (when window is focused) |
| , / . | Step to previous / next frame |
| Alt + , / Alt + . | Jump to previous / next keyframe |
Make an Object Fly in a Large Arc
-
1Create the object. GameObject → 3D Object → Cube. Rename it Flyer. Position it at
(-5, 0.5, 0). -
2Open Animation window. Select Flyer in Hierarchy → press Ctrl/Cmd + 6. Click the Create button in the centre of the window. Save as
FlyArc.animinAssets/Animations/. -
3Enable Record. Click the red ● at top-left of the Animation window. The Scene view border turns red — Unity is now recording.
-
4Set keyframe at frame 0. Playhead should already be at 0:00. In the Inspector, with the cube still at
(-5, 0.5, 0), right-click the Position label → Add Key. A diamond appears in the timeline. -
5Set keyframe at 1 second (peak of arc). Drag the playhead to 1:00. In the Scene or Inspector, change the Cube's position to
(0, 5, 0). Unity adds a keyframe automatically. -
6Set keyframe at 2 seconds (landing). Drag playhead to 2:00. Change position to
(5, 0.5, 0). -
7Stop recording. Click the red ● again. Press Play at the top of Unity — the cube should fly in an arc from left to right.
-
8Make it loop. In the Project window, find
FlyArc.anim. In the Inspector tick Loop Time. The animation now repeats forever.
The default linear interpolation makes the cube travel in a sharp triangle, not a smooth arc. Open the Curves tab at the bottom of the Animation window. Find the Position.y curve. Right-click each keyframe → set tangent to Auto or Free Smooth. The Y curve becomes a smooth parabola — a real arc.
Drag the tangent handles in the Curves view to make the cube fly higher, slower, or with a gravity-like fall. The shape of the curve is the shape of the motion.
Make an Object Flicker
-
1Create the object. GameObject → 3D Object → Sphere. Rename to Flicker. Position at
(0, 1, 0). -
2New animation clip. With Flicker selected, open Animation window. Click Create. Save as
FlickerOnOff.anim. -
3Add the Enabled property. In the Animation window, click Add Property (left side, below playback controls). A list appears. Expand Mesh Renderer → click the + next to Enabled. Two keyframes are added automatically — both with value 1 (true).
-
4Toggle some keyframes off. Click the second keyframe diamond at the end of the clip. In the Inspector, untick the Mesh Renderer → Enabled box. The keyframe value becomes 0.
-
5Add more flicker keyframes. Drag playhead to 0:15 (half a second). Right-click in the timeline at the Mesh Renderer.Enabled row → Add Key. Toggle the renderer enabled state in the Inspector to alternate. Repeat at 0:30, 0:45, 1:00 — switching the state each time.
-
6Tick Loop Time on the clip asset.
-
7Press Play. The sphere blinks on and off at irregular intervals — like a faulty light.
In the Curves tab, the m_Enabled curve is a step function — it doesn't interpolate between 0 and 1, it snaps. Boolean and integer animation values always behave this way regardless of tangent settings.
Make an Object Appear to Morph
-
1Create the object. GameObject → 3D Object → Capsule. Rename to Morpher. Position at
(3, 1, 0). -
2Create a unique material. Project window → right-click → Create → Material. Name it
Mat_Morpher. Set Albedo colour to bright blue. Drag it onto the Morpher in the Hierarchy. -
3Important — duplicate the material per object. If you want to animate this material without affecting other objects, ensure it's only used by this one GameObject. (Animating a shared material affects everything that uses it.)
-
4New animation clip. Select Morpher → Animation window → Create. Save as
Morph.anim. -
5Enable Record. Click the red ●.
-
6Frame 0 keyframes. Playhead at 0:00. In the Inspector, set Scale to
(1, 1, 1). Right-click Scale label → Add Key. Then click the material's Albedo colour swatch and set it to blue — keyframe is added automatically because Record is on. -
7Frame 1:00 — bigger and red. Drag playhead to 1:00. Set Scale to
(2, 2, 2). Change material Albedo to red. -
8Frame 2:00 — squashed and yellow. Drag playhead to 2:00. Set Scale to
(2.5, 0.5, 2.5). Change material Albedo to yellow. -
9Frame 3:00 — back to start. Drag playhead to 3:00. Set Scale back to
(1, 1, 1)and colour back to blue. This makes the loop seamless. -
10Stop recording. Tick Loop Time. Press Play. Watch your capsule pulse, squash, and shift through colours.
The Standard Shader uses property name _Color (older) while URP/HDRP shaders use _BaseColor. If your colour keyframes don't seem to do anything, check the property path in the Animation window — it should match what your Material's shader actually exposes. The Built-in Render Pipeline (default for 3D Core template) uses _Color.
Welcome to Mecanim
Mecanim is the name for Unity's animation system above the level of single clips. It uses a visual state machine to control which animation plays when, based on parameters your scripts can set.
| Concept | What it is | Example |
|---|---|---|
| State | An animation clip the object can be in | Idle, Walk, Run, Jump |
| Transition | The arrow between states; a rule for switching | Idle → Walk when Speed > 0.1 |
| Parameter | A variable that drives transitions | Speed (Float), IsGrounded (Bool) |
| Condition | The rule on a transition that uses a parameter | "Speed Greater 0.1" |
Without a state machine, you'd write if/else trees in code to choose which animation to play. State machines move that logic into a visual editor — easier to reason about, easier to extend, and animators (non-programmers) can edit it.
The Animator Controller
An Animator Controller (.controller file) is the asset that holds your state machine. Every animated GameObject references one through its Animator component.
Anatomy of the Animator Window
Default State (Orange)
The state coloured orange is the default — Unity automatically transitions into it when the Animator starts. To change which state is default, right-click any state → Set as Layer Default State.
The Four Parameter Types
| Type | Use For | Set From Script |
|---|---|---|
| Float | Continuous values (speed, blend amount) | animator.SetFloat("Speed", 5f) |
| Int | Discrete categories (weapon ID, level) | animator.SetInteger("Weapon", 2) |
| Bool | On/off states that persist (IsGrounded) | animator.SetBool("IsOpen", true) |
| Trigger | One-shot events (jump, attack, fire) | animator.SetTrigger("Attack") |
A Bool stays on until you turn it off (good for "is this character currently running?"). A Trigger auto-resets to false the moment its transition fires (good for "fire weapon now"). Use Trigger for one-time events to avoid getting stuck.
Transitions and Conditions
Creating a Transition
-
1Right-click the source state → Make Transition. A white arrow follows your cursor.
-
2Click the destination state. The arrow connects.
-
3Select the arrow. In the Inspector, click + under Conditions. Choose a parameter and a comparison.
Important Transition Settings
| Setting | What it does | Recommendation |
|---|---|---|
| Has Exit Time | Transition only fires after the source clip plays to a certain point | Untick for responsive controls (jump, attack). Tick for "play this clip fully first" cases. |
| Transition Duration | Cross-fade time between clips, in seconds | 0.1–0.25s for smooth blending; 0 for snap cuts. |
| Conditions | Parameter rules that must all be true to fire | Use Triggers for one-shot, Bools for sustained, Floats for thresholds. |
Build It: An Opening Door
Put everything together. You'll build a door that opens when the player presses Space and closes when pressed again.
State Diagram
default
door rotated 90°
Step-by-Step
-
1Build the door. Create an empty GameObject named DoorPivot at
(0, 0, 5). Add a Cube as child, position(0.5, 1, 0), scale(1, 2, 0.1). The pivot lets the door swing on its hinge edge. -
2Create two clips. Select DoorPivot. In Animation window: Create → save as
Door_Closed.anim. This clip should keep rotation Y at0for both keyframes (1 second long). -
3From the clip dropdown in the Animation window → Create New Clip → save as
Door_Open.anim. Record. Frame 0: rotation Y = 0. Frame 1:00: rotation Y = 90. -
4Open Animator window. Window → Animation → Animator. With DoorPivot selected you'll see both clips already in the controller. Right-click Door_Closed → Set as Layer Default State.
-
5Add a Bool parameter. Parameters tab → + → Bool → name it IsOpen.
-
6Make transitions. Right-click Door_Closed → Make Transition → click Door_Open. Select the new arrow. In Inspector: untick Has Exit Time, set Transition Duration to
0.1. Add Condition: IsOpen = true. -
7Make the reverse transition. Right-click Door_Open → Make Transition → Door_Closed. Same settings but condition: IsOpen = false.
-
8Write the controller script. See the script below. Attach to DoorPivot.
// DoorController.cs // ───────────────────────────────────────────────────────────────────────────── // Toggles the IsOpen Animator parameter when the player presses Space. // The Animator handles the visual transition automatically. // ───────────────────────────────────────────────────────────────────────────── using UnityEngine; public class DoorController : MonoBehaviour { private Animator animator; private bool isOpen = false; void Awake() { animator = GetComponent<Animator>(); } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { isOpen = !isOpen; animator.SetBool("IsOpen", isOpen); } } }
Press Play. Press Space — the door swings open. Press Space again — it closes. You've built your first state-machine-driven animation.
Common Problems
| Symptom | Likely Cause | Fix |
|---|---|---|
| Animation window says "To begin animating, select a GameObject" | No GameObject selected, or selected object has no animation yet | Click your GameObject in the Hierarchy first. |
| Pressing Record changes nothing | The Animation window isn't in focus, or the playhead is at a position with no keyframes | Click inside the Animation window first; ensure playhead is at a sensible time. |
| Object snaps back to start when Play stops | Normal Unity behaviour — the scene reloads when you exit Play mode | This is correct. Animations only persist visually during Play. |
| Animation plays once, then stops | Loop Time not ticked on the clip asset | Select the .anim file → Inspector → tick Loop Time. |
| Transition fires but visual doesn't change | Has Exit Time is ticked, blocking instant transition | Untick Has Exit Time on the transition. |
| Material colour change doesn't animate | Wrong shader property name (Standard uses _Color, URP uses _BaseColor) | Check the Animation window's property path matches the actual shader property. |
| Multiple objects all change colour together | They share a Material asset | Duplicate the material per object, or use MaterialPropertyBlock from script. |
| Door rotates around its centre, not its edge | The Cube's pivot is at its centre, not on the hinge side | Use a parent empty GameObject as the pivot, with the Cube offset as a child. |
Extension Challenges
| ⭐ Difficulty | Challenge | New Concept |
|---|---|---|
| ⭐ | Add a third keyframe to your Flying Arc that makes the cube tilt during flight | Multi-property keyframes |
| ⭐ | Add a sound effect that plays when the door opens (use Animation Events) | Animation Events |
| ⭐⭐ | Build a traffic light: Red → Green → Yellow → Red, each lasting 3 seconds, using only animation | Multiple states + transition timing |
| ⭐⭐ | Make the door auto-close 3 seconds after opening (no second key press needed) | Time-based transition or coroutine + parameter |
| ⭐⭐⭐ | Build a Blend Tree that blends Idle → Walk → Run based on a Speed float parameter | Blend Trees, 1D blending |
| ⭐⭐⭐ | Add an "Any State" transition that interrupts whatever is playing to fire a Hit reaction | Any State transitions |
| ⭐⭐⭐⭐ | Import a free humanoid character from the Asset Store and set up a basic Idle/Walk/Run state machine driven by WASD input | Humanoid rigs, Avatar masking, Mecanim with locomotion |
Continue Studying Mecanim
Your Hour 18 task is to keep exploring. The official Unity documentation is the canonical reference — bookmark these pages.
| Topic | Unity Manual Page |
|---|---|
| Animation system overview | docs.unity3d.com/Manual/AnimationSection.html |
| Animator Controller | docs.unity3d.com/Manual/AnimatorControllers.html |
| Animation State Machines | docs.unity3d.com/Manual/AnimationStateMachines.html |
| Animation Parameters | docs.unity3d.com/Manual/AnimationParameters.html |
| Blend Trees (advanced blending) | docs.unity3d.com/Manual/class-BlendTree.html |
| Animation Curves | docs.unity3d.com/Manual/animeditor-AnimationCurves.html |
You've worked with the Animation window, animated multiple property types, built a state machine, and connected it to a script. Mecanim has many more layers (Blend Trees, IK, layers, masks) — but the foundation you've built today is what every animated Unity game stands on.