# Animation - Generic > **Notice:** The complete sample source code is available on GitHub: > **[github.com/unigine-engine/cpp-api-samples](https://github.com/unigine-engine/cpp-api-samples)**. ## Animation Layers Playback This sample demonstrates composing a single animation out of several reusable sequences using *[AnimationChannelSubSequence](../../../api/library/animations/timeline/class.animationchannelsubsequence_cpp.md)* - a channel that holds other sequences as clips, with each clip having its own start time and duration. Three single-parameter sequences are created first: a Z position bounce, a rotation around the Z axis, and a scale pulse. They are then combined in two different ways, and both results are played at the same time: - The **left box** plays the clips starting at the same time, so its position, rotation, and scale are animated simultaneously. - The **right box** plays the clips one after another. A clip that has finished stops writing its parameter, and the box keeps the value it was left with. Both players use the same three sequences. Instead of duplicating them for each box, every player enumerates the binds of its sequences, including the ones inside the clips, and points them at its own box, so the sequences remain reusable and are not changed themselves. Composing animations out of reusable pieces makes it possible to build complex animation scenarios from a small set of simple sequences and reuse them for any number of objects. **SDK Path:***/source/animation_generic/animation_layers_playback* ## Bones: Rotation [Animation Graph] This sample demonstrates how to combine skeletal animation playback with direct modification of bone transforms. The turret plays an idle animation, over which the left and right shooting animations are blended additively by a state machine in the *[animation graph](../../../content/animations/index.md)*. On top of that, the horizontal joint of the turret is rotated from code at a constant speed. The rotation is applied after the animation graph has written its pose, so that the played animation does not overwrite it. Combining played animations with programmatic bone control is useful for turrets and other cases where part of a skeleton has to be driven by code rather than by a pre-made animation. **SDK Path:***/source/animation_generic/bones_rotation* ## Curve2D Animation This sample demonstrates animating node transformations and material parameters with *[Curve2D](../../../api/library/common/class.curve2d_cpp.md)* values sampled every frame. Two components are shown: - **CurveAnimationTransform** - animates the transformation of a node. Position, rotation, and scale have a separate curve for each of the X, Y, Z axes, so every axis can be shaped independently. The curves are evaluated at the current time and composed into the final transformation matrix. In the sample it moves the platforms, and changes the coins and heart transformations. - **CurveAnimationMaterialParamFloat** - animates float parameters of a material. Each entry of the list binds a curve to a parameter by its name and surface index, so any number of parameters can be animated at once. In the sample it pulses the emission of the coins and the heart. The curves and the playback speed are available in the properties of the corresponding component in UnigineEditor, where the curves can also be shaped in the *[Curve Editor](../../../editor2/curve_editor/index.md)*. This setup is useful for looping motions and dynamic material effects that do not require external animation assets. **SDK Path:***/source/animation_generic/curve2d_animation* ## Global Engine Parameters Animation This sample demonstrates animating global Engine parameters using **singleton channels** - animation channels that have no bind and target a global system instead of a certain node, material, or property. Two parameters are animated at the same time by a single *[AnimationSequence](../../../api/library/animations/timeline/class.animationsequence_cpp.md)*: the Z component of physics gravity and the alpha component of the render background color. Their current values are displayed in the *State* window. The sequence is saved to a `.seq` file in the `sequences` folder of the world and then played back right from this file, demonstrating a serialization roundtrip. If the file is unavailable, the sequence stored in memory is played instead. Animating global parameters gives you programmatic control over scene effects, weather changes, time transitions, and physical properties, resulting in more engaging and interactive scenes. > **Notice:** All of the animation sequences, players and objects are managed by the animation system and have the "Engine lifetime", i.e. they exist from the point they're loaded or created to when the Engine shutdowns, and therefore are preserved between different worlds. > > > You have to stop active players when switching to another world, if you don't want them continue playing there. **SDK Path:***/source/animation_generic/global_engine_parameters_animation* ## Material Parameters Animation This sample illustrates how to change the parameters of *[materials](../../../api/library/rendering/class.material_cpp.md)* at runtime. Each object in the scene has its own component that animates one of the parameters continuously: - **[Albedo color](../../../content/materials/library/mesh_base/index.md#parameter_albedo)** - smoothly transitions between two colors. - **[Albedo texture](../../../content/materials/library/mesh_base/index.md#texture_albedo)** - alternates between two textures loaded from files. - **[Metalness](../../../content/materials/library/mesh_base/index.md#parameter_metalness)** - smoothly transitions between two values. - **[Emission](../../../content/materials/library/mesh_base/index.md#option_emission)** state - is switched on and off, making the object blink. - **[Cast World Shadow](../../../editor2/node_parameters/visual_representation/index.md#cast_world_shadows)** state - is switched on and off, making the shadow of the object appear and disappear. The parameters can be edited in the properties of the corresponding components in UnigineEditor. The current value of every animated parameter is displayed in the *State* window. Changing material parameters at runtime is the basis for various dynamic effects, such as highlighting the objects the user interacts with, indicating the state of a device, or reproducing the changes of a surface over time. **SDK Path:***/source/animation_generic/material_parameters_animation* ## Node Parameters Animation This sample demonstrates animating the transformation of a node using **node binds** - *[AnimationBindNode](../../../api/library/animations/timeline/class.animationbindnode_cpp.md)* objects that point animation channels at a certain node, identified by its ID and name. A box is animated by three channels of different types added to a single *[AnimationSequence](../../../api/library/animations/timeline/class.animationsequence_cpp.md)*, all of them sharing the same bind: - *[AnimationChannelScalar](../../../api/library/animations/timeline/class.animationchannelscalar_cpp.md)* - animates a single float value, here the Z position of the box. - *[AnimationChannelQuat](../../../api/library/animations/timeline/class.animationchannelquat_cpp.md)* - animates rotation via quaternion interpolation. Along with the quaternion mode used here, the rotation can also be composed of three separate curves for each of the angles. - *[AnimationChannelFVec3](../../../api/library/animations/timeline/class.animationchannelfvec3_cpp.md)* - animates a three-component vector, here the scale of the box. The position channel gets its keyframes from an *[AnimationCurveScalar](../../../api/library/animations/timeline/class.animationcurvescalar_cpp.md)* curve created explicitly, while the other two channels take the values directly. The keys use smooth interpolation based on a Bezier curve, so the box moves and resizes with easing instead of linearly. The current values of the animated parameters are displayed in the *State* window. Node animations can serve as a foundation for various effects, including element appearance/disappearance, rotations, resizing, and more. **SDK Path:***/source/animation_generic/node_parameters_animation* ## Physics-Based Animation This sample demonstrates several ways of moving an object towards a target smoothly, shown as a simple game. The sample has two modes, switched with the buttons in the description window. In the **Animations Demo** mode, the way of moving is selected from the drop-down list, with each of them implemented as a separate component: - **Linear** - moves at a constant speed. - **EaseIn** - accelerates gradually. - **EaseInOut** - accelerates at the start and decelerates at the end. - **EaseOut** - decelerates gradually. - **EaseOutElastic** - oscillates around the destination before settling on it. - **EaseOutBack** - overshoots the destination slightly and comes back to it. - **EaseOutBounce** - bounces at the destination. In the **Start Game** mode, you control the laser pointer with the mouse, and the cat chases it using spring simulation, becoming faster and more responsive over time until it catches the pointer. The parameters of each way of moving are available in the properties of the corresponding component in UnigineEditor. Easing and spring-based motion make the movement of objects look natural, which is useful for cameras, UI elements, followers, and any object that has to reach a moving target smoothly. **SDK Path:***/source/animation_generic/physics_based_animation* ## Property Animation This sample demonstrates two ways to animate property parameters: through code or with a sequence created in the **[Sequencer](../../../editor2/tools/sequencer/index.md) tool** - a visual interface for editing keyframes without writing animation setup code. Two boxes illustrate these approaches by changing their rotation speed and direction over time. In both cases, the animation changes a parameter that defines rotation speed. The rotation logic reads this value each frame and rotates the box accordingly: - For **Sequence created via code**, the **PropertyAnimationSample** component creates an animation of the *speed* parameter of the `speed_prop` property. - For **Sequence created in Editor**, a `.seq` file created in the Sequencer tool stores the animation for the *angular_velocity* parameter of the **Rotator** component. The *Status* section displays the current speed values, showing that both approaches produce the same results. Use either approach to control custom behavior over time, such as movement speed, effect intensity, or simulation settings. The animation defines how parameter values change, while components determine how to use them. Multiple components can read the same animated parameter to coordinate their behavior. In `PropertyAnimationSample.cpp`, an [AnimationChannelFloat](../../../api/library/animations/timeline/class.animationchannelfloat_cpp.md) is bound to the property parameter using [AnimationBindPropertyParameter](../../../api/library/animations/timeline/class.animationbindpropertyparameter_cpp.md) and played by an [AnimationSequencePlayer](../../../api/library/animations/timeline/class.animationsequenceplayer_cpp.md). The `rotation_speed.seq` sequence uses [AnimationBindComponent](../../../api/library/animations/timeline/class.animationbindcomponent_cpp.md) to animate the Z component of **Rotator.angular_velocity** and is played by a [NodeSequencePlayer](../../../api/library/nodes/class.nodesequenceplayer_cpp.md). **SDK Path:***/source/animation_generic/property_animation* ## Sequence Events This sample demonstrates handling **[events](../../../editor2/tools/sequencer/channel_reference/events/index.md)** placed on the timeline in the **[Sequencer](../../../editor2/tools/sequencer/index.md)** tool. A ball bounces along the platform, with a **hit** event placed at each landing. When playback reaches an event, the sample draws a red circle around the ball and displays the event data in the *Status* section. Each event additionally carries an integer payload identifying the landing point, from 0 to 4. This index is passed to the handler during playback,and can be used to select different responses to events with the same name. Use sequence events to coordinate animation with other actions, such as playing a sound or triggering an effect on contact or updating simulation state when an animated mechanism reaches a target position. The `ball_bounce.seq` sequence contains the ball animation and an event channel. In `SequenceEventsSample.cpp`, the sample obtains the [AnimationSequencePlayer](../../../api/library/animations/timeline/class.animationsequenceplayer_cpp.md) from a [NodeSequencePlayer](../../../api/library/nodes/class.nodesequenceplayer_cpp.md) node and subscribes to its *Triggered* event using *getEventTriggered()*. The handler checks the event name and uses its integer payload. See *[Events Channel](../../../editor2/tools/sequencer/channel_reference/events/index.md)* for details on configuring sequence events. **SDK Path:***/source/animation_generic/sequence_events* ## Sequence in Node Reference This sample demonstrates sharing a single animation sequence across multiple [Node Reference](../../../objects/nodes/reference/index.md) instances. In the scene, three references to the same `.node` file contain a sphere moving around a capsule and each instance has its own sequence player, so pausing one animation does not affect the others. The *Parameters* section provides a checkbox for each to pause or resume playback. The sequence animates the sphere's local position, allowing instances to be placed at different locations without modifying the animation itself. Use this approach to populate a scene with repeated animated objects, such as surveillance cameras, background traffic, or NPCs performing routine actions, without configuring the animation separately for each instance. The `example.node` file contains a [NodeSequencePlayer](../../../api/library/nodes/class.nodesequenceplayer_cpp.md) and its animated objects. It plays `orbit.seq`, which moves the sphere around the capsule. In `SequenceInNodeReferenceSample.cpp`, the sample accesses the player inside each node reference and connects its playback controls to the corresponding checkbox. **SDK Path:***/source/animation_generic/sequence_in_node_reference* ## Sequence Playback This sample demonstrates playback of an animation created in the [Sequencer](../../../editor2/tools/sequencer/index.md) tool. A sequence loaded from a `.seq` file uses separate channels to animate a box's position, rotation, and scale. The *Parameters* section lets you start or pause playback, view the animation at a selected time, adjust its speed, play it backwards (speed < 0), and enable looping. *Stop* resets playback time and restores the box's original state. The *Status* section displays whether playback is active and the sequence duration. Use sequence playback for cutscenes, scripted object movement, and animated mechanisms, with playback controlled by the user or application logic. In `SequencePlaybackSample.cpp`, an [AnimationSequencePlayer](../../../api/library/animations/timeline/class.animationsequenceplayer_cpp.md) loads `box_motion.seq` from the component's *Sequence File* parameter. When the playback time is changed, *applyCurrentFrame()* updates the box even if playback is paused or stopped. **SDK Path:***/source/animation_generic/sequence_playback* ## Sequence Play on Enable This sample demonstrates how the *Play On Enable* and *Restart On Enable* options control animation playback when a **[NodeSequencePlayer](../../../api/library/nodes/class.nodesequenceplayer_cpp.md)** node is enabled. Two boxes use the same lifting animation with different playback settings: - **Play On Enable** preserves playback time, so the animation resumes from where it paused. - **Restart On Enable** additionally resets playback time, so the animation starts from the beginning. Both players use the same `box_lift.seq`, with the *Restart On Enable* player overriding the animation binding to target another box. The *Status* section displays each player's playback time. Configure *Play On Enable* and *Restart On Enable* to automatically resume or restart animations when objects are enabled, without separate playback commands in code, for example, by enabling a node from a trigger. In `SequencePlayOnEnableSample.cpp`, the *Players Enabled* checkbox enables or disables the players using *setEnabled()*; playback is handled by the settings on each player. See [Sequence Player](../../../objects/animations/sequence_player/index.md) for details. **SDK Path:***/source/animation_generic/sequence_play_on_enable* ## Tracker: Playback This sample demonstrates playing back animation tracks created in the **[Tracker](../../../editor2/tools/tracker/index.md)** tool and stored in `.track` files. Three tracks are played at the same time, animating the position, rotation, and scale of the object independently. The position and rotation tracks are listed in the properties of the **Tracker** component and loaded on its initialization, while the scale track is added later by the **TrackPlayback** component. The tracks are addressed in two different ways: by their ID, cached once at initialization, and by their name, which is more readable but requires a lookup on every call. Each track keeps its own playback time, advanced every frame and wrapped back to the beginning at the end of the track. Tracker comes in handy for creating complex animation scenarios, where the animation is authored visually rather than in code. The **Tracker.cpp** file provides a ready-to-use C++ interface to the **Tracker** system, which the **TrackPlayback** component works through. If you want to reuse the sample in your own projects as is, copy the files together with the `tracker_wrapper.h` script from the `usc_code` folder that it relies on. **SDK Path:***/source/animation_generic/tracker_playback* ## Widget Animation This sample demonstrates animating widgets using *[AnimationBindRuntime](../../../api/library/animations/timeline/class.animationbindruntime_cpp.md)*, a bind that stores the runtime instance of a target object. It can point an animation channel at any Engine object, such as a widget, a body, or a camera. A looped title animation is played on three labels: the **Player 0** and **Player 1** labels are animated by position, font color, and font size, while the **vs** label between them is animated by font color only. A channel animates a single parameter, so a label animated by several parameters at once needs a separate channel for each of them, with the same bind assigned to all of them. Animating interface elements programmatically helps create more lively, appealing user interfaces and enables automation of their behavior. **SDK Path:***/source/animation_generic/widget_animation*