Controlling Timelines with code

addam davis
3 min readMay 15, 2023

--

Objective: Control when your Timeline Animations begin with inputs!

If you have been following along, we have created several Timelines that play on awake. In this tutorial I’m going to show you a simple way to control the start time of your Timeline with inputs.

To begin, create your empty object and make it your director by selecting it and creating a Timeline.

Next you will want to create your animations. I’m making a light bulb blowing animation. I made an animation of the ceiling light shaking after the bulb blows.

Next, I created an animation track for the point light that I’m using for the scene. I made a key frame with the intensity set to 1 then had it gradually brighten until it peaks then go to zero instantly.

After that I added a SFX for when the bulb goes out. After adding the audio, line it up with the animations.

This is great, we now have an animation of the bulb charging brighter then busting and shaking. To control when this Timeline starts, we need to select it and, in the inspector, turn off “Play on Awake.”

Now let’s create a new script and attach it to the Director object. In the script we need to add the UnityEngine.Playables library.

Keeping with the simple aspects we have going on here let's create a serialized variable for “Playable Director.”

Finally, in the update we place a check for input, I used the ‘K’ key, and if the ‘K’ key is pressed we want to play the playable director.

That’s all there is to it. Now when you play your editor your Timeline will play when you press the assigned key.

--

--