Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 36 ยท Animation and Audio

Timeline and Cinemachine in Unity

Build cutscenes with Unity Timeline and drive smart cameras with Cinemachine - tracks, clips, PlayableDirector, virtual cameras, damping and blends - with runnable stand-ins.

Two Unity packages turn a pile of animated objects into something that looks directed. Timeline is a sequencer: you place animation, audio, activation and signal clips on tracks and play them together, like a small video editor inside Unity. Cinemachine is a camera system: instead of scripting camera movement by hand, you describe what the camera should follow and look at, and it handles the motion.

Neither runs on this page because Unity is not available here. The Unity setup is described in words and read-only code; the runnable C# stand-ins reproduce the core ideas (a track scheduler and camera damping).

Timeline basics

Create a Timeline with Assets > Create > Timeline, add a Playable Director component to a game object and assign the asset; open the Timeline window (Window > Sequencing > Timeline). A timeline contains tracks, each bound to a scene object:

  • Animation Track: plays animation clips on an Animator (a character walking to a door).
  • Activation Track: enables or disables a game object during a time range.
  • Audio Track: plays AudioClips at exact times.
  • Control Track: controls nested timelines or particle systems.
  • Signal Track: emits signals, markers that call a method through a SignalReceiver (open the door, start dialog).
  • Cinemachine Track: switches between virtual cameras (below).

Clips on a track can overlap, and overlapping clips blend over the overlap, which gives smooth crossfades between animations. You play a timeline from code:

C#
using UnityEngine;
using UnityEngine.Playables;

public class IntroCutscene : MonoBehaviour
{
    [SerializeField] PlayableDirector director;
    [SerializeField] GameObject playerControls;

    void Start()
    {
        playerControls.SetActive(false);
        director.stopped += OnFinished;
        director.Play();
    }

    void OnFinished(PlayableDirector d)
    {
        d.stopped -= OnFinished;
        playerControls.SetActive(true);
    }
}

Set Wrap Mode to None for a one-shot cutscene, Loop for ambient motion, Hold to freeze on the last frame. The time property lets you jump, and Evaluate() applies the state at the current time without playing.

A scheduler you can run

What does the Director do each frame? It advances a time value and, for every clip whose range contains that time, tells the track to evaluate it. A minimal version:

C# Stand-in: a tiny Timeline

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Cinemachine in a nutshell

Cinemachine (in Unity 6, Cinemachine 3) replaces the single main camera with two layers:

  • The real Camera has a Cinemachine Brain component. It looks at all virtual cameras and puts the camera where the highest-priority one says.
  • CinemachineCamera objects (virtual cameras) hold the rules. Each has a Tracking Target, a Look At Target and a Position Control and Rotation Control mode, such as Follow (keep an offset), Third Person Follow, Orbital Follow (free look), Position Composer (keep the target inside the screen), Rotation Composer and Hard Look At.

Important settings are damping (how lazily the camera catches up), dead zone (the screen area where the target can move without the camera reacting) and soft zone (where the camera starts moving, gently). Together they remove the stiff, robotic look of a camera glued to a player.

Switching camera is a priority change: enable a boss-fight camera with a higher Priority and the Brain blends to it using the Default Blend (an ease-in-out over, say, 1.5 seconds). Disable it and the old camera takes over again. Other useful pieces:

  • Cinemachine Confiner 2D/3D keeps the view inside the level bounds.
  • Impulse Source / Listener for screen shake from an explosion.
  • Cinemachine Target Group frames several targets at once.
  • Spline Dolly moves the camera along a path for fly-throughs.
C#
using Unity.Cinemachine;
using UnityEngine;

public class BossArea : MonoBehaviour
{
    [SerializeField] CinemachineCamera bossCamera;

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player")) bossCamera.Priority = 20;   // normal camera is 10
    }

    void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player")) bossCamera.Priority = 0;
    }
}

How damping feels

Damping is an exponential smoothing: every frame the camera closes a fraction of the remaining gap. The stand-in shows why it must be frame-rate independent: if you use the same factor per frame, a 120 fps player gets a snappier camera than a 30 fps one. Unity's Damper uses the time step to fix that.

C# Stand-in: frame-rate independent camera damping

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The first three lines agree no matter the frame rate; the naive lerp results differ widely. This is the same trap as moving without Time.deltaTime.

Putting them together

A typical cutscene uses a Cinemachine Track on the Timeline with several virtual cameras: each clip activates one camera, and overlapping clips set the blend. Animation, music and signals sit on other tracks. During gameplay the Brain simply follows the player camera. The result: designers can edit a cutscene visually without touching code, and the gameplay camera needs no scripts at all.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which component plays a Timeline asset?

    The Playable Director holds the Timeline asset and the bindings of tracks to scene objects.
  2. 2. What does the Cinemachine Brain do?

    The Brain sits on the Camera and obeys the active CinemachineCamera.
  3. 3. What is a Timeline signal used for?

    Signals are markers that trigger methods through a SignalReceiver, for example to open a door.
  4. 4. Why should camera damping use the time step?

    A fixed per-frame factor makes high frame rates snappier; time-based smoothing is frame-rate independent.

Summary

  • Timeline sequences animation, audio, activation and signals on tracks driven by a Playable Director.
  • Overlapping clips blend; director.stopped tells you when a cutscene ends.
  • Cinemachine splits the camera into a Brain and priority-driven virtual cameras with damping, dead zones and confiners.
  • Time-based smoothing keeps cameras consistent across frame rates.

Next: 2D Workflow: Sprites and Tilemaps