COIT20271 · Week 9 Lab Tutorial

🎬 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.

Animation Window
Keyframes
Animation Curves
Mecanim
Animator Controller
State Machines
3 Sandbox Exercises
Introduction

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.

HourActivitySkill Built
17Make a cube fly around in a large arcPosition keyframes, animation curves
17Make a sphere flicker (renderer on/off)Animating boolean component properties
17Morph an object via scale and material changeAnimating multiple properties at once
18Build an Animator Controller for a doorStates, transitions, parameters
🧪
Sandbox mindset

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

Step 0

Project Setup

  1. 1
    Open Unity Hub → New Project → 3D (Core). Name it AnimationLab. Click Create.
  2. 2
    In the Project window, create folders: Assets/Animations, Assets/Scripts, Assets/Materials.
  3. 3
    Save the open scene as SandboxScene in Assets/Scenes/.
  4. 4
    Add a Plane at origin (GameObject → 3D Object → Plane) so animated objects have a visible ground reference.
Step 1

Animation Fundamentals — 5 Things to Know

1. Two Different Windows

WindowOpen viaPurpose
AnimationWindow → Animation → AnimationEdit a single clip — set keyframes, curves, properties
AnimatorWindow → Animation → AnimatorEdit the state machine — connect clips, parameters, transitions
⚠️
Animation ≠ Animator

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:

Your GameObject + Animator component (auto-added) Animator Controller .controller asset (auto-created) Animation Clip .anim asset (your file) One click in the Animation window does all three.

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

ShortcutAction
Ctrl/Cmd + 6Toggle Animation window
KAdd a keyframe at current time (when window is focused)
, / .Step to previous / next frame
Alt + , / Alt + .Jump to previous / next keyframe
Hour 17 · Exercise 1

Make an Object Fly in a Large Arc

1
Flying Arc
Position keyframes + curve smoothing
~10 min
Position keyframes Animation Curves Loop Time
  1. 1
    Create the object. GameObject → 3D Object → Cube. Rename it Flyer. Position it at (-5, 0.5, 0).
  2. 2
    Open Animation window. Select Flyer in Hierarchy → press Ctrl/Cmd + 6. Click the Create button in the centre of the window. Save as FlyArc.anim in Assets/Animations/.
  3. 3
    Enable Record. Click the red at top-left of the Animation window. The Scene view border turns red — Unity is now recording.
  4. 4
    Set 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.
  5. 5
    Set 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.
  6. 6
    Set keyframe at 2 seconds (landing). Drag playhead to 2:00. Change position to (5, 0.5, 0).
  7. 7
    Stop recording. Click the red again. Press Play at the top of Unity — the cube should fly in an arc from left to right.
  8. 8
    Make it loop. In the Project window, find FlyArc.anim. In the Inspector tick Loop Time. The animation now repeats forever.
🎯
Tweak the curve for a real arc

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.

🎨
Try this

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.

Hour 17 · Exercise 2

Make an Object Flicker

2
Flicker Effect
Cycle MeshRenderer.enabled on/off
~7 min
MeshRenderer.Enabled Boolean keyframes Add Property
  1. 1
    Create the object. GameObject → 3D Object → Sphere. Rename to Flicker. Position at (0, 1, 0).
  2. 2
    New animation clip. With Flicker selected, open Animation window. Click Create. Save as FlickerOnOff.anim.
  3. 3
    Add 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).
  4. 4
    Toggle 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.
  5. 5
    Add 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.
  6. 6
    Tick Loop Time on the clip asset.
  7. 7
    Press Play. The sphere blinks on and off at irregular intervals — like a faulty light.
💡
Why boolean curves look "stepped"

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.

Hour 17 · Exercise 3

Make an Object Appear to Morph

3
Scale + Material Morph
Animate scale and material colour together
~12 min
Transform.Scale Material Color Multi-property animation
  1. 1
    Create the object. GameObject → 3D Object → Capsule. Rename to Morpher. Position at (3, 1, 0).
  2. 2
    Create 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.
  3. 3
    Important — 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.)
  4. 4
    New animation clip. Select Morpher → Animation window → Create. Save as Morph.anim.
  5. 5
    Enable Record. Click the red .
  6. 6
    Frame 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.
  7. 7
    Frame 1:00 — bigger and red. Drag playhead to 1:00. Set Scale to (2, 2, 2). Change material Albedo to red.
  8. 8
    Frame 2:00 — squashed and yellow. Drag playhead to 2:00. Set Scale to (2.5, 0.5, 2.5). Change material Albedo to yellow.
  9. 9
    Frame 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.
  10. 10
    Stop recording. Tick Loop Time. Press Play. Watch your capsule pulse, squash, and shift through colours.
⚠️
If colour doesn't animate

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.

Hour 18

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.

ConceptWhat it isExample
StateAn animation clip the object can be inIdle, Walk, Run, Jump
TransitionThe arrow between states; a rule for switchingIdle → Walk when Speed > 0.1
ParameterA variable that drives transitionsSpeed (Float), IsGrounded (Bool)
ConditionThe rule on a transition that uses a parameter"Speed Greater 0.1"
🎓
Why state machines?

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.

Mecanim · Part 1

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.

Mecanim · Part 2

The Four Parameter Types

TypeUse ForSet From Script
FloatContinuous values (speed, blend amount)animator.SetFloat("Speed", 5f)
IntDiscrete categories (weapon ID, level)animator.SetInteger("Weapon", 2)
BoolOn/off states that persist (IsGrounded)animator.SetBool("IsOpen", true)
TriggerOne-shot events (jump, attack, fire)animator.SetTrigger("Attack")
🔑
Bool vs Trigger — the key distinction

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.

Mecanim · Part 3

Transitions and Conditions

Creating a Transition

  1. 1
    Right-click the source state → Make Transition. A white arrow follows your cursor.
  2. 2
    Click the destination state. The arrow connects.
  3. 3
    Select the arrow. In the Inspector, click + under Conditions. Choose a parameter and a comparison.

Important Transition Settings

SettingWhat it doesRecommendation
Has Exit TimeTransition only fires after the source clip plays to a certain pointUntick for responsive controls (jump, attack). Tick for "play this clip fully first" cases.
Transition DurationCross-fade time between clips, in seconds0.1–0.25s for smooth blending; 0 for snap cuts.
ConditionsParameter rules that must all be true to fireUse Triggers for one-shot, Bools for sustained, Floats for thresholds.
Mecanim · Practical

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

Closed
default
IsOpen = true
Open
door rotated 90°
IsOpen = false

Step-by-Step

  1. 1
    Build 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.
  2. 2
    Create two clips. Select DoorPivot. In Animation window: Create → save as Door_Closed.anim. This clip should keep rotation Y at 0 for both keyframes (1 second long).
  3. 3
    From 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.
  4. 4
    Open 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.
  5. 5
    Add a Bool parameter. Parameters tab → + → Bool → name it IsOpen.
  6. 6
    Make 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.
  7. 7
    Make the reverse transition. Right-click Door_Open → Make Transition → Door_Closed. Same settings but condition: IsOpen = false.
  8. 8
    Write the controller script. See the script below. Attach to DoorPivot.
DoorController.cs C# · 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);
        }
    }
}
Test

Press Play. Press Space — the door swings open. Press Space again — it closes. You've built your first state-machine-driven animation.

Help

Common Problems

SymptomLikely CauseFix
Animation window says "To begin animating, select a GameObject"No GameObject selected, or selected object has no animation yetClick your GameObject in the Hierarchy first.
Pressing Record changes nothingThe Animation window isn't in focus, or the playhead is at a position with no keyframesClick inside the Animation window first; ensure playhead is at a sensible time.
Object snaps back to start when Play stopsNormal Unity behaviour — the scene reloads when you exit Play modeThis is correct. Animations only persist visually during Play.
Animation plays once, then stopsLoop Time not ticked on the clip assetSelect the .anim file → Inspector → tick Loop Time.
Transition fires but visual doesn't changeHas Exit Time is ticked, blocking instant transitionUntick Has Exit Time on the transition.
Material colour change doesn't animateWrong 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 togetherThey share a Material assetDuplicate the material per object, or use MaterialPropertyBlock from script.
Door rotates around its centre, not its edgeThe Cube's pivot is at its centre, not on the hinge sideUse a parent empty GameObject as the pivot, with the Cube offset as a child.
Going Further

Extension Challenges

⭐ DifficultyChallengeNew Concept
Add a third keyframe to your Flying Arc that makes the cube tilt during flightMulti-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 animationMultiple 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 parameterBlend Trees, 1D blending
⭐⭐⭐Add an "Any State" transition that interrupts whatever is playing to fire a Hit reactionAny State transitions
⭐⭐⭐⭐Import a free humanoid character from the Asset Store and set up a basic Idle/Walk/Run state machine driven by WASD inputHumanoid rigs, Avatar masking, Mecanim with locomotion
Hour 18 Self-Study

Continue Studying Mecanim

Your Hour 18 task is to keep exploring. The official Unity documentation is the canonical reference — bookmark these pages.

TopicUnity Manual Page
Animation system overviewdocs.unity3d.com/Manual/AnimationSection.html
Animator Controllerdocs.unity3d.com/Manual/AnimatorControllers.html
Animation State Machinesdocs.unity3d.com/Manual/AnimationStateMachines.html
Animation Parametersdocs.unity3d.com/Manual/AnimationParameters.html
Blend Trees (advanced blending)docs.unity3d.com/Manual/class-BlendTree.html
Animation Curvesdocs.unity3d.com/Manual/animeditor-AnimationCurves.html
🎉
You've completed Animation Lab!

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.