12 Weeks with Unity: Week 11 - The Timeline and Cinemachine

May 28, 2018 at 10:34 pm by -gToon

This is the eleventh of a series of articles that cover my journey learning and exploring one of the most powerful indie game creation tools available - Unity. I’ll be sharing my knowledge and discoveries over a 12 week period. Each week I’ll post primarily on the process of learning Unity 3D along with other topics such as the history of the game engine, the community, and prominent artists/creators. Last week we covered the Particle System in Unity and watched a great introduction video from YouTube artist Brackeys.

I’ve been learning Unity using the Lynda.com course, “Unity 3D Essential Training” by Craig Barr as a guide. At this point, I’m nearing the end of the course

The Unity Timeline

I had some mistaken notions about the process and tools used to create cutscenes in Unity. Thanks to Craig Barr’s tutorial and further research I was able to get my thinking straight. But that’s part of learning Unity, so I’ll give myself a break. :-)

Back in 2017 Unity released two excellent tools for creating cutscenes: the Timeline and Cinemachine. With Cinemachine, Unity created a system of cameras that allowed users to do all kinds of amazing camera movement and tracking. And with the Timeline, Unity users had a simple system for animating game objects and cameras in order to create cutscene cinematics or in-game animation sequences. For more detailed information on both check out the Unity manual here and here. Keep in mind that Cinemachine is a free plugin and the Timeline editor comes packaged with Unity.

Working with the Timeline

In the Unity 3D Essential project I’ve been using for this article series, we have a scene that takes place inside of a hazardous materials warehouse. Our main character is a guy in a hazmat suit who is also the game player proxy. Using the timeline, the tutorial takes you through the process of setting up an in-game sequence. The sequence consists of setting up a trigger (to start the sequence) which when triggered causes game objects to animate in a specific way. In the scene, it’s a large anti-hazard box which travels on a rail to the spot where a small barrel of hazardous material has spilled on the floor. Once it arrives over the spill it drops down on the floor covering the spill and protecting our main character. What makes Timeline so special is that it visually arranges tracks that are directly related to game objects in your scene. And since everything in Unity is a game object you can animate everything using the Timeline.

Setting up and animating with the Timeline

As usual within Unity, you can either create an empty game object and then add a timeline to the object, or you can add a Timeline to an already existing game object as a component of that object. In our case, we’ll be adding a trigger pad model to the scene and then adding the Timeline as a component. Once we select our trigger pad object, we a shown a screen that asks us to create a Director component and a Timeline asset. Now, Unity saves all of your instances of a timeline and their connections to any game objects you may have along with the project. We won’t go into the details now, but you can check the Unity manual for more specifics.


Now that we have a working timeline we can start to animate game objects. In our scene, we’ll make the container a child of the crane by simple drag and drop in the Hierarchy window. Now we’ll add rigid body physics to the container (so it will drop down to the ground when we want it to). Note that there is a checkbox in the rigid body component that says “is Kinematic”. If we check this box, the container will not fall, but if we uncheck it the container falls according to the gravity physics we’ve set up. Check the box so that we can use Timeline to cause it to stop when we want it to.

Next, we add physics/box collider to our pad and shape it so when the player steps on the pad it triggers the animation we’ll create in the timeline. Be sure to check the box “is trigger” so that it works with the Timeline. Note that we’ll add a simple Trigger script once we create the animation we want in the Timeline. We then add the crane and the container to the Timeline using simple drag and drop. You’ll be asked if you want to add it as an activation track, animation track, and an audio track: choose animation track.

Unity gives you the ability to record your animations by clicking on the red record button. Now move the container (attached to the crane now) over to a spot directly above the hazard spill. Be sure to move the playhead over to about 600 frames so you’ll have a keyframe at the start and one at the end. There’s a nice curves editor to the left of the record button which enables you to easily adjust the movement of the crane/container. In our case, we’ll turn off the record button then adjust the curve so that the container arrives at the spill and then hovers over it for a bit.

Moving on to the crane, we’ll add a simple trigger script (provided by the Lynda.com course) by drop n’ drag to the crane object in the Inspector. Be sure to uncheck the “play on awake” box in the Inspector window so that the animation doesn’t start until you trigger in by stepping on the pad. Another important detail is to tag your 3rd person controller component as a “player” because in the script it will be looking for “player” to trigger. At this point, we can hit play in the game window which takes us in-game. Now we run to the pad which triggers the timeline to play the container moving over the hazard spill and then dropping the container over the spill. Works like a charm.


Unfortunately, I’ve written a longer section for the Timeline, so I don’t have time to go into detail about Cinemachine. I did find a great tutorial on Unity’s YouTube channel which covers Cinemachine, so I’ll share it with you here. One last thought: with Timeline and Cinemachine you have a simple but powerful system to create not only cut-scenes but in-game sequences that can include any game object. The possibilities really stimulate the imagination. I hope to pursue this further after the 12 Weeks series is over.


Next Week: Series Wrap-Up

Top Stories

This website uses cookies to ensure you get the best experience possible More Info
Got it!