When it comes to creating cinematic content, Unity’s Timeline offers a pretty versatile solution for triggering animations and audio, activating GameObjects, and switching between cameras (or ‘virtual cameras’ specifically). The Timeline window lets us visualise and adjust timings fairly easily, and we can even create some smooth transitions between different cameras (by dragging the start or end of one clip into another).
Once you have the Cinemachine package imported, you can open up the Timeline window through Window > Sequencing > Timeline. I’d recommend selecting an empty GameObject to be the parent for a cutscene ‘group’ (containing your actors, any virtual cameras, and even cutscene-specific UI with its own canvas). With this selected, choose to Create a new Timeline asset.
You should see an Animator track on the Timeline, as well as an Animator component on the object the Director’s on — neither of which I’ve needed so far (so you’re welcome to remove them and start afresh). By placing the director on this sort of parent object, the idea is that all we should need to do to trigger the cutscene is to set this object to active (causing the Timeline to automatically run, triggering any of the tracks within it at the appropriate times).
From the Timeline view, you can right click in the left column to create new ‘tracks’. As a brief overview (at least of the ones I’ve used so far):
- Activation Track. Can be used to control the active state of a GameObject. For instance, if you want an object in the scene to simply ‘appear’ or disappear, such as an animated actor or a prop.
- Animation Track. This is a particularly useful and versatile track: we can drag in a GameObject to the empty Animator slot and allow Unity to create an animator component on it. Once this is done, we can hit the red record button in and move the slider along and create key frames (as we would within the Animation window). While recording, we can even select groups of objects and animate them at the same time. While I don’t believe we can edit/move/delete key frames within the Timeline view, just double click on the track in the right column and it should open up the Animation dope sheet.
- Audio Track. This is probably one of the fairly self-explanatory ones: it’s a Timeline track that can play AudioClips from a specified AudioSource. It can be a quick and handy way of ensuring audio plays at the right time for our cutscenes.
- Cinemachine Track. This one’s currently tucked away under ‘Cinemachine.Timeline’ but is pretty invaluable when it comes to working with virtual cameras. We need to specify a Cinemachine ‘brain’, which I believe get’s added to the Main Camera by default. As with most of these tracks, right click in the right column and choose one of the appropriate ‘Add’ options (in this case, ‘Add Cinemachine Shot’). You then just need to specify the desired Virtual Camera in the inspector and you should be ready to start deciding when you switch to different shots in your scene.
Just to wrap up, the Timeline’s definitely worth trying out if you fancy doing some cinematic sequences in your games, and getting to easily navigate through a sequence frame by frame or millisecond by millisecond makes it really, really easy for us get the timings just right in our animations, shots, and audio in particular. As an example of how I’m using this in one of the cutscenes, as well as how I’m structuring the project in the hierarchy, I’ve included a screenshot from the editor below 😉