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

Creating Reusable Timeline Assets

Develop modular timeline assets that can be instantiated and triggered across different levels or game scenarios.

In this lesson, you will learn how to design modular Timeline assets that act as templates, allowing you to trigger the same cinematic sequence across multiple levels without manual reconstruction.

The Problem with "Hard-Coded" Timelines

When you create a Timeline asset directly on a GameObject in your scene, that sequence is bound to the specific objects in that hierarchy. If you try to drag that Timeline into a different scene, the references will break because the new scene doesn’t contain the exact same GameObjects. To make a Timeline truly reusable, you must decouple the track data from the specific scene objects.

Designing for Reusability

The secret to reusable Timelines lies in Exposed References. When you add an object to a track (like a Cinemachine Track or an Animation Track), Unity creates an entry in the Timeline’s binding list. By using a "Template" approach, you can create a generic Timeline asset that doesn't care about the specific objects until runtime.

Instead of manually assigning objects in the Inspector for every single level, you can use a script to inject the references at runtime:

using UnityEngine;
using UnityEngine.Playables;

public class TimelineTrigger : MonoBehaviour
{
    public PlayableAsset templateTimeline;
    public GameObject targetPlayer;
    public CinemachineVirtualCamera sceneCamera;

    void Start()
    {
        PlayableDirector director = GetComponent<PlayableDirector>();
        director.playableAsset = templateTimeline;

        // Bind the tracks to objects in the current scene
        director.SetGenericBinding(director.playableAsset.outputs.First().sourceObject, targetPlayer);
    }
}

Implementing Modular Logic

To make your Timelines truly modular:

  1. Use Prefabs for Actors: Keep your cinematic characters as prefabs. When the Timeline triggers, it will look for an instance of that prefab rather than a specific object ID.
  2. Utilize Signal Emitters: Instead of placing logic directly on a timeline track, use Signal Emitters to send generic messages. Because the signal receiver is in your scene, the Timeline remains "dumb"—it just sends the signal, and your scene-specific managers decide what to do with it.

By treating your Timelines as data-driven assets rather than scene-dependent objects, you can build a library of high-quality cinematics that work anywhere in your project.

Key Takeaway: Decouple your Timeline from scene-specific objects by using script-based binding or Signal Emitters, allowing a single asset to be recycled across your entire game.