Animation Player
Plays an animation clip on its node and the nodes below it: property tracks, sprite frames and events. Clip time, gameplay events and tracks other than the transform pose advance on fixed steps, so a replay gives the same result at any frame rate.
component animation.AnimationPlayer
Art Studio
Try it
Play the run clip
The real Animation Player starts the eight-frame run clip at speed 0. Loop is set to once, so the last frame remains after playback.
Change Speed from 0 to 8 to play the clip quickly. Reset restores the first frame and speed 0.
Scene3 nodes
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Clip | AnimClip | none | Clip to play. |
| Play On Start | bool | true | Starts the clip when Play starts. |
| Speed | float | 1 | Playback speed: 1 is normal, 2 twice as fast; a negative speed plays backwards. |
| Loop | enum | clip | clip keeps the loop mode of the clip; once, loop and pingPong override it. one of: clip, once, loop, pingPong |
| Time Domain | enum | game | game follows game time and pauses with it; unscaled runs in real time while paused, for menus and other presentation. one of: game, unscaled |
Runtime state
Values the component has while the game runs. They are not saved with the scene.
| Name | Type | Default | Description |
|---|---|---|---|
| Time | float | 0 | Time inside the clip, in seconds. |
| Playing | bool | false | Whether the clip plays. |
| Cycle | int | 0 | Cycles of a looping clip so far. |
Methods
Pause method
func (AnimationPlayer) Pause()
Holds the clip where it is.
Play method
func (AnimationPlayer) Play(clip AssetRef<anim>)
Starts a clip from its beginning on the next fixed step; nil plays the current clip again.
Example
node.Get<AnimationPlayer>().Play(Attack)
Resume method
func (AnimationPlayer) Resume()
Continues a paused clip.
Seek method
func (AnimationPlayer) Seek(time float)
Jumps to a time inside the clip on the next fixed step without firing the events in between.
SetSpeed method
func (AnimationPlayer) SetSpeed(speed float)
Changes the playback speed; a negative speed plays backwards.
Stop method
func (AnimationPlayer) Stop()
Ends the clip on the next fixed step: tracks with onEnd=restore get back the values they had before Play, Finished runs with cycle -1.
Signals
Event signal
signal Event(id int, payload float)
Runs when the clip reaches an event; anim.EventName(id) gives its name.
Finished signal
signal Finished(cycle int)
Runs when a clip that does not loop ends, with cycle 0, or after Stop, with cycle -1.
Script events
Scripts on a node with this component receive these events from the Animation module.
OnAnimEvent— Runs on the scripts of a node whose Animation Player reaches an event of its clip; anim.EventName(id) gives the name.
Related guides
- Animation An animation clip changes properties of a node and its children over time: sprite frames, colors, transforms, script fields.
- Animation Player Animation Player plays its Clip, from the start of Play when Play On Start is set.