Animations With Sequencer
Objects in a three-dimensional world are designed to move. And making them move can be done not only with user input or AI implementation, it can be done with animation. Surely, if you've played games, you've noticed small clips between game episodes, in which movement in the frame is performed according to a certain scenario, like in a movie, or stunning camera fly-throughs displaying shining cars before a race start. To add such dynamic gameplay elements or create in-game cinematic cut-scenes, UNIGINE has the Sequencer tool that allows creating animations based on keyframes. It gives developers the ability to:
- Easily create key frames for all nodes in the world, as well as animate movements, camera parameters, and all available render settings.
- Set up day-night shift and weather conditions change.
- Switch between cameras, change the field of view on the fly, and play sounds and music for creating professional cinematics.
- Animate interactive objects in the game, for example, lighting a torch, opening a door, or moving a platform.
- Apply post-processing effects such as DOF, Motion blur, SSR, etc. All these effects can be fine-tuned for each camera view.
- Animate fields of your own components and fire events that your game logic responds to.
- And much more.
The Sequencer window includes the following elements: a toolbar with controls for saving and loading, playback and sequence settings, a working area with the list of animated parameters and the timeline, and a properties panel displaying the settings of the selected item. The timeline is shown in two views: the Dope Sheet shows when the parameter changes happen, while the Curves editor shows how the values change over time.
Key Frame Animation#
An animation created in Sequencer is called a sequence and is stored as a *.seq file. A sequence consists of a number of channels, and each channel indicates how one parameter changes over time. A channel can control a global setting (for example, a render one) or can be bound to a specific object: a node in the world, a material, a property, or a component. This object is called the channel's target. If you need to animate multiple parameters of one node at the same time, simply create multiple channels for it. For example, you can use channels to create animations that:
- Move nodes, play skeletal animation, control emission of particles, etc.
- Change any material settings and modify parameters for various configurable effects. For example, you can change the texture and material reflectivity to create the rain effect.
- Change rendering settings: change the background color, apply post-process effects, control stereo and much more.
- Set up cameras.
Most channels store keys (see below), but some of them hold clips instead: blocks of ready-made content placed on the timeline, such as a camera to look through, a sound, a character animation, or even another sequence.
Key Frames#
A channel is composed of key frames (or simply keys), which are snapshots of the parameter value at a certain time during the animation. Each key frame stores a time and the parameter change (new parameter value or enabled/disabled state). For example, for a node position channel, a key frame specifies a new node position along one of the axes; for a node enable channel, a key frame indicates whether the node is enabled or disabled.
Between two neighboring keys, the value changes along a curve, and the shape of this curve depends on the key type. The values can be switched abruptly or smoothly interpolated:
- Linear interpolation can be used, for example, for a node scaling channel.
- Smooth interpolation by a Bezier curve will provide a smooth trajectory for a node position channel.
In the Sequencer window, you can change the type of the selected keys via the context menu or in the properties panel, where you can also set the key parameters (time and value).
| Auto Flat |
Automatic smoothing. The curve flattens at the key, so the value slows down when approaching the key and speeds up after it. This type is assigned to the first key of a channel, further keys take the type of the previous key. No control points are available as the curve is smoothed automatically.
|
|---|---|
| Linear |
Linear interpolation. The value changes along a straight line to the next key at a constant rate.
|
| Smooth |
Smooth interpolation by Bezier curve. The curve passes through the key without a kink. There are two control points (tangents) available for each key, and they always mirror each other.
|
| Aligned |
Smooth interpolation with different easing. The same as Smooth, but the two control points can have different lengths, so the value can ease in and out of the key differently.
|
| Break |
Interpolation with independent control points. The curve can turn a corner at the key, as the two control points of the key are moved independently.
|
| Constant |
No transition. The key value remains constant up to the next key, where it abruptly changes.
|
The control points are dragged in the Curves editor. To delete the selected keys, press Delete. When you drag keys along the timeline, they can snap to frames and to other keys: snapping is toggled by the Snap button on the toolbar.
Practice#
Now let's try to create a sequence for animating the camera movement (so called fly-through) in our interior scene, for this purpose let's open the scene in the editor.
To open the Sequencer tool, choose Tools → Sequencer from the main menu.
The tool opens with a new sequence ready for editing. First, let's set the duration of our clip: click the gear button on the toolbar to open the sequence settings.
Set Time Format to Seconds and Sequence Duration to 12: our clip will last 12 seconds. By the way, the Playback Speed parameter is used as a speed multiplier, using it alone you can make the clip play faster or slower.
Now let's create channels that will animate the movement of our camera:
- A new sequence already contains a Node › Position channel that is not bound to any object. We don't need it, so select it and press Delete.
-
Select the camera (Player) node in the World Nodes window. Then right-click the Position parameter in the Parameters window and choose Set Key in Sequencer. This will create a Node › Position channel bound to the camera, with a key storing the current camera position.
-
Now let's do the same for the Rotation parameter (we will change the camera rotation as well). Then select the new rotation channel and in the properties panel set Rotation Mode to Angles XYZ.
- Next, we need the sequence to show the scene through our camera. Click + above the channel list and choose Camera Cuts. This channel switches between cameras over time and holds clips instead of keys, each clip being a camera.
-
Double-click the Camera Cuts row to add a clip and drag the camera node from the World Nodes window to the Camera field of the clip in the properties panel. Then drag the right edge of the clip to the end of the sequence, so that the camera stays active for all 12 seconds.
Now everything is ready to start working with keys directly. You can add keys manually by double-clicking a channel row and set their time and values in the properties panel, but we'll make it easier. Turn on Auto-Key
on the toolbar: from now on, every time you move or rotate the camera, its new position and rotation are recorded as keys at the current playhead position. Note that each time you move the playhead, the camera takes the position stored in the sequence for this moment, but in between you can move it freely.
Then do the following:
-
Select Game Camera in the viewport camera list: now the viewport shows the scene through the camera made active by the Camera Cuts channel (that is, our camera), and you control this camera directly. Make sure the playhead is at the beginning of the timeline and, controlling the camera, set it to the first position and rotate it as you want.
- As soon as you release the mouse button, Sequencer automatically records the current camera position and rotation to the keys at the playhead position. The first key point is ready!
-
Repeat the same for other points: move the playhead to the next point in time (say, 2 seconds later), then move and rotate the camera, and new keys will be added automatically. Continue moving the camera along the trajectory approximately demonstrated in the image below.
-
All keys are created with the Auto Flat type, so the camera slows down at each of them. To make the camera fly through the intermediate points without stopping, change the type of these keys to Smooth and adjust their control points in the Curves editor, so that the curves pass through the keys at an angle instead of flattening out.
-
When all points are placed, you can play the sequence using the playback controls on the toolbar or by pressing Space. To play it repeatedly, enable Loop.
To adjust the trajectory, move the playhead to the desired key using the Previous Key / Next Key arrows in the channel row and change the camera position and rotation: the key will be updated automatically.
The last thing left to do is to save our sequence, so that it can be used further (for example, to play the fly-through from code, as in cutscenes).
To save the sequence to a *.seq file, click Save (or press Ctrl + S) and in the dialog box that opens, specify the name of the sequence file — let's call it camera_animation.seq and save it to the data/sequences folder.
All channels of the sequence (as we have for rotation, movement and camera switching) are saved to a single *.seq file.
To load a previously saved sequence, click Load and select the sequence file in the dialog box that opens, or simply double-click the sequence asset in the Asset Browser.
You can also combine several sequences stored in different files into one by using the Sub-Sequence channel and make complex video scenes.
To play the sequence in the world, add a Sequence Player node (Create → Animation → Sequence Player), assign camera_animation.seq to it in the Parameters window, and enable the Play On Enable option: the fly-through will start as soon as the world is loaded. To start it at a certain moment (for example, when the player enters a room), control its playback from code.
The information on this page is valid for UNIGINE 2.22 SDK.