An Introduction to Timeline and Simple Animation in Unity
Over the past several articles, we have seen how powerful Cinemachine virtual cameras are. Now it’s time to pair them up with Unity’s Timeline editor and Virtual Director, to unleash true cinematic power.
Timeline is a non-linear editor, that gives you control over cameras, animations, music, sound FX and more. View the Timeline editor by navigating to Window>Sequencing>Timeline.
Create an empty object to hold your Timeline controls.
For simplicity, this one is named Timeline_01.
There is a drone object (Filebase Asset Library) in the scene that I will be using to make a simple Timeline animation.
I need to create a Director component, as asked here in the Timeline window upon opening. With the Timeline_01 object selected in the Hierarchy, go to this Timeline window and press the create button.
Make a folder called Directors inside the project assets folder, and use this to store your timeline Director.
Now in the Assets folder there will the stored Timeline Director asset.
Now the timeline window shows the editor rather than prompting the user to make a director.
If you select the timeline director asset in the Assets folder, the inspector will reveal some additional options.
You can set your target Frame Rate and Duration Mode. The Duration can be Based on Clips or set to a Fixed Length.
The Timeline_01 object now has a Playable Director component. Let’s explore these options one by one. The Playable assignment is currently the Timeline_01 asset, but this can be reassigned as you see fit.
DSP Clock: Has to do with the playback speed of an Audio Source.
Game Time: The Director will be affected by scaled game time.
Unscaled Game Time: Director will not be affected by scaled game time.
Play on Awake: Timeline animation will automatically play when enabled.
Hold: Stop at end of the timeline.
Loop: Repeat timeline in an infinite animation loop.
None: Play once then reset back to the beginning.
Initial Time: Time to wait before playing the timeline
Bindings: Objects associated with timeline. This will automatically populate as you add objects to the timeline.
The editor itself has a play button, skip to next frame button and fast forward/ rewind to the end/ beginning of clip buttons.
The gear box icon has a lot more options, including the ability to set your target frame rate. You can also change the Timeline between displaying in frames or seconds.
The Plus icon enables to user to add various Tracks to the Timeline editor.
This tab offers a display for Markers, as well as buttons to dictate how the timeline is inserted.
I want to create a simple object animation, so I choose to add an Animation Track to the Timeline editor.
This empty Animation Track is looking for an object assignment to animate.
Another way to do this, is to simply drag the object you want to animate from the hierarchy into the Timeline editor (on the left where the tracks appear), while the Timeline_01 object is selected. A prompt appears to ask what kind of Track you would like to insert. I choose the Animation Track.
Now the drone object is now already assigned when the Animation Track appears.
The drone also has an Animator component automatically attached to it.
Press the record button on the Animation Track to start animating!
The drone is set to the desired starting position, and the timeline marker is set at the beginning. You can move the object in the scene view to generate a key frame, or you can go to the inspector and right-click on the Transform Position and select Add Key.
The starting position here is the front left side of the room when facing inwards.
I move to the 10 second mark to create another key for the end position of the animation. If the end and the beginning positions are the same, it makes for a nice looping animation.
The drone is moved to a new position in the front right before adding a New Key.
I want it to move in a square pattern, so the process continues by positioning the drone after moving to the desired place in the timeline editor.
The back left corner is the final position to be entered.
The animation can be previewed by scrubbing through the timeline with the marker.
After stopping the recording, keyframes for the animation can be seen in the timeline editor.
Double-clicking them in Timeline will open the related animation. Keyframes can be adjusted as needed.
Once the animation is complete, right-click on the keyframes in timeline and select Convert to Clip Track.
The Clip Track shows more options in the inspector. Let’s take a look at the Speed Multiplier. This number can be adjusted to change the playback speed of your animation, rather than diving into the animation itself and repositioning keyframes.
There are also options to Ease In and Ease Out of animation movements.
If you prefer, rather than using the inspector to set these values, the ctrl button can be held while dragging in from each side of the animation clip to add the ease effect.
I want this animation to loop, so I set the Wrap Mode to Loop.
The Rotation of the drone is now animated to finish off the look.
Here is a little drone on patrol in the lab!
I hope you join me in my next article where I add more animations to this drone object, as well as some quick tips for the Timeline editor. Thanks for reading!