Working with Unity Timeline
We have learnt what Control Track are and how to they can receive other timeline data and trigger it as an Regular Track on the Timeline. But what about communication with scripts and objects outside the Timeline? This is where Signal Emitters come in handy.
What are Signal Emitters:
Signal Emitters are very similar to Animation Events where you are able to trigger an script on the selected event when the scrubber passes through. With Signal Emitters they will be relying on Timeline Markers, these markers can be toggled to view in the last icon on the top left corner of the timeline window.
To Add an Signal Emitter to the Timeline, scrub through the precise duration that you wish to add an emitter and right click the top bar (near the numbers). A new drop down menu will appear which should have the function to add an Signal Emitter.
The Signal Emitter should look like an Animation event and by selecting the pin the Inspector will have settings which you can adjust. The settings also include creating and Adding new Signal Receivers.
By Default you shouldn't have any signal emitters created, therefore will need to create an new Signal. Once you do, Unity will prompt you to save the signal in a safe known location within the project.
Once you do that the Inspector will update and provide you with a Signal Receiver Component.
The Signal Receiver is the component that will trigger whatever Emitter is placed in the slot, this can be scripts or even game objects.
To demonstrate this, I have created a basic script that will be attached to an capsule game object. This script basically has an public method that calls upon a Debug Log.
Once that drag the capsule game object into the Signal Receiver slot I am able to call upon the public function. In this example I named the script “Debug_Emitter” and the public function “Emitter Test” and they were both found within the drop down menu.
Now when we test out the scene, you will see in the console that the debug will be triggered once the scrubber passes the signal emitter marker.
Signal Emitters in Practical Application:
Signal Emitters and Receivers can be almost applied to everything, they are easy to use and simple to track. Some examples of practical applications are “Timed Events” during a Timeline playback. The Timeline can play an prompt asking the player to press an certain button or do an certain action, and the Emitter can keep track of the progress, If the player doesn’t meet the requirements then the Emitter can be set to stop the timeline and vice versa.
Signal Emitters can also be used in Timeline Playback sequence as well, since with Emitters you can also gain access to the Timeline Director itself and control the Play and Pause function of the timeline.
Controlling the Timeline Director With Emitters:
Using the same script or creating an new script, I will need to gain access to the Timeline either way. This can be accessed via using the UnityEngine Playables library and also setting the playable director as an component.
Then with simple Timeline Controls, I created two new public methods that contain Pause and Play functions.
I set the Input for the keyboard “K” to trigger the Play Again Method.
Then I set the Signal Emitter to trigger the Pause Method.
Now whenever the scrubber toggles the Emitter event, it will pause the Timeline. And whenever I press the “K” button on my keyboard the Timeline would resume playback.