Using Signal Emitters in Timeline to Alter Playback — Unity

Objective: To learn how to make Playback adjustments using Signal Emitters in Unity’s Timeline.

Controlling Playback through code

By accessing our Playback controls from Timeline through code, we are able to create some runtime scenarios such as pausing a cinematic cutscene with the spacebar or holding down the Esc key to end the cutscene prematurely.

Let’s take a look at how to get this setup in your next game.

Setting up the Basic Scene

First we need to be able to access the Playback controls through our script, so let’s get this setup. I am going to be using option 2 to setup our signal emitter from this article, so we can look at a different approach to this.

I have a very basic scene, with a plane, and a prefab model/animation from mixamo. I have then created a PlayableDirector() component on this prefab, along with a new Timeline. I have then dragged the prefab into the Timeline window and selected Signal Track’. This will automatically create a Signal Receiver component on the prefab.

At the same time I have dragged the animation for the model into the Timeline window and created an Animation Track so we can watch the dance pause when the signal emits.

Scene
Timeline window — Added a Signal Track and an Animation Track with an Animation Clip
Prefab Inspector window

Creating the Script

Let’s make this as basic as possible just to show it’s purpose.

Playable Director script

First, we need to access the Playables namespace so we can access the built-in PlayableDirector class.

Then, we need to make the variable _playDirector visible in the Inspector so we can assign it by using the [SerializeField] class. Don’t forget to now go into the Inspector window and assign the prefab to this slot.

Next, let’s grab the component. Attach this script to your prefab. As the script is on our prefab, we can simply grab the component without having to find the game object first.

Lastly, let’s create a public method that is going to tell us in the Console window when it has triggered and also let’s use the built-in method for the PlayableDirector class that pauses Timeline.

Your prefab should now have all these components:

Prefab components

Setting up the Signal Emitter

If you are unsure how to get this setup, click on this article. Let’s place the Signal Emitter somewhere in the middle of the animation.

Adding a Signal Emitter to the Timeline

Let’s create a new Signal Asset for the ‘Emit Signalfield in the Inspector for the newly created Signal Emitter.

Creating a new Signal Asset for the Emit Signal field

Adding a Reaction to the Signal Receiver

Hit the ‘Add Reactionbutton, then where it says ‘No Function’, click on the drop down box and navigate your way to the public method that was created in the Playback script.

Adding a reaction to the Signal Receiver

If you want to be able to see the game pause in the editor when pressing Play’ in the Timeline window, then click this option. Otherwise you will always need to press the normal Playbutton and watch it happen at runtime:

Editor and Runtime toggle switch

Let’s Test it!

Wonderful! Works a treat.

The Signal Receiver is reacting to the Signal Emitted and and behaving accordingly.

Let’s Get the Cutscene Going Again!

Let’s create some input for the player — By pressing the ‘F’ key during runtime, the player will be able to play the cutscene again using the PlayableDirectors class built-in Play() method.

Player input for playing the cutscene after it was paused
Playing the Timeline sequence again after pressing the ‘F’ button

--

--

--

Passionate Unity Game Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Calling REST-APIs with Retrofit and MVVM architecture.

SRP is the MEDUSA of Clean code family

How to Scan A File for Viruses in Salesforce Apex

CS373 Spring 2022: Ruchi Bhalani Week 5

The Perfect Pair

Critical Making Summary: Fall 2019

#freestockphoto (Monday 23rd 02AM)

Telegram bots are easy!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Hilton

Chris Hilton

Passionate Unity Game Developer

More from Medium

What is a Signal Emitter in Timeline

Understanding Frustum and Occlusion Culling in Unity3D

IK Weapon System in Unity

Unity : Raycast (Part III)