Table of Contents

Class Animation

Holds data that can be used to animate anything in the engine.

Inheritance
Animation

Remarks

This resource holds data that can be used to animate anything in the engine. Animations are divided into tracks and each track must be linked to a node. The state of that node can be changed through time, by adding timed keys (events) to the track.

# This creates an animation that makes the node "Enemy" move to the right by
# 100 pixels in 2.0 seconds.
var animation = Animation.new()
var track_index = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(track_index, "Enemy:position:x")
animation.track_insert_key(track_index, 0.0, 0)
animation.track_insert_key(track_index, 2.0, 100)
animation.length = 2.0

Animations are just data containers, and must be added to nodes such as an AnimationPlayer to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check TrackType to see available types.

Note: For 3D position/rotation/scale, using the dedicated Animation.TYPE_POSITION_3D, Animation.TYPE_ROTATION_3D and Animation.TYPE_SCALE_3D track types instead of Animation.TYPE_VALUE is recommended for performance reasons.

See Also

Properties

capture_included

Returns true if the capture track is included. This is a cached readonly value for performance.

var capture_included : bool = false

Property Value

bool

Remarks

  • bool is_capture_included

length

The total length of the animation (in seconds).

Note: Length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.

var length : float = 1.0

Property Value

float

Remarks

loop_mode

Determines the behavior of both ends of the animation timeline during animation playback. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.

var loop_mode : int = 0

Property Value

int

Remarks

  • void set_loop_mode(int value)
  • int get_loop_mode

step

The animation step value.

var step : float = 0.0333333

Property Value

float

Remarks

Methods

add_marker(StringName, float)

Adds a marker to this Animation.

void add_marker(StringName name, float time)

Parameters

name StringName
time float

add_track(int, int)

Adds a track to the Animation.

int add_track(int type, int at_position)

Parameters

type int
at_position int

animation_track_get_key_animation(int, int)

Qualifiers: const

Returns the animation name at the key identified by key_idx. The track_idx must be the index of an Animation Track.

StringName animation_track_get_key_animation(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

animation_track_insert_key(int, float, StringName)

Inserts a key with value animation at the given time (in seconds). The track_idx must be the index of an Animation Track.

int animation_track_insert_key(int track_idx, float time, StringName animation)

Parameters

track_idx int
time float
animation StringName

animation_track_set_key_animation(int, int, StringName)

Sets the key identified by key_idx to value animation. The track_idx must be the index of an Animation Track.

void animation_track_set_key_animation(int track_idx, int key_idx, StringName animation)

Parameters

track_idx int
key_idx int
animation StringName

audio_track_get_key_end_offset(int, int)

Qualifiers: const

Returns the end offset of the key identified by key_idx. The track_idx must be the index of an Audio Track.

End offset is the number of seconds cut off at the ending of the audio stream.

float audio_track_get_key_end_offset(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

audio_track_get_key_start_offset(int, int)

Qualifiers: const

Returns the start offset of the key identified by key_idx. The track_idx must be the index of an Audio Track.

Start offset is the number of seconds cut off at the beginning of the audio stream.

float audio_track_get_key_start_offset(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

audio_track_get_key_stream(int, int)

Qualifiers: const

Returns the audio stream of the key identified by key_idx. The track_idx must be the index of an Audio Track.

Resource audio_track_get_key_stream(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

audio_track_insert_key(int, float, Resource, float, float)

Inserts an Audio Track key at the given time in seconds. The track_idx must be the index of an Audio Track.

stream is the AudioStream resource to play. start_offset is the number of seconds cut off at the beginning of the audio stream, while end_offset is at the ending.

int audio_track_insert_key(int track_idx, float time, Resource stream, float start_offset, float end_offset)

Parameters

track_idx int
time float
stream Resource
start_offset float
end_offset float

audio_track_is_use_blend(int)

Qualifiers: const

Returns true if the track at track_idx will be blended with other animations.

bool audio_track_is_use_blend(int track_idx)

Parameters

track_idx int

audio_track_set_key_end_offset(int, int, float)

Sets the end offset of the key identified by key_idx to value offset. The track_idx must be the index of an Audio Track.

void audio_track_set_key_end_offset(int track_idx, int key_idx, float offset)

Parameters

track_idx int
key_idx int
offset float

audio_track_set_key_start_offset(int, int, float)

Sets the start offset of the key identified by key_idx to value offset. The track_idx must be the index of an Audio Track.

void audio_track_set_key_start_offset(int track_idx, int key_idx, float offset)

Parameters

track_idx int
key_idx int
offset float

audio_track_set_key_stream(int, int, Resource)

Sets the stream of the key identified by key_idx to value stream. The track_idx must be the index of an Audio Track.

void audio_track_set_key_stream(int track_idx, int key_idx, Resource stream)

Parameters

track_idx int
key_idx int
stream Resource

audio_track_set_use_blend(int, bool)

Sets whether the track will be blended with other animations. If true, the audio playback volume changes depending on the blend value.

void audio_track_set_use_blend(int track_idx, bool enable)

Parameters

track_idx int
enable bool

bezier_track_get_key_in_handle(int, int)

Qualifiers: const

Returns the in handle of the key identified by key_idx. The track_idx must be the index of a Bezier Track.

Vector2 bezier_track_get_key_in_handle(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

bezier_track_get_key_out_handle(int, int)

Qualifiers: const

Returns the out handle of the key identified by key_idx. The track_idx must be the index of a Bezier Track.

Vector2 bezier_track_get_key_out_handle(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

bezier_track_get_key_value(int, int)

Qualifiers: const

Returns the value of the key identified by key_idx. The track_idx must be the index of a Bezier Track.

float bezier_track_get_key_value(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

bezier_track_insert_key(int, float, float, Vector2, Vector2)

Inserts a Bezier Track key at the given time in seconds. The track_idx must be the index of a Bezier Track.

in_handle is the left-side weight of the added Bezier curve point, out_handle is the right-side one, while value is the actual value at this point.

int bezier_track_insert_key(int track_idx, float time, float value, Vector2 in_handle, Vector2 out_handle)

Parameters

track_idx int
time float
value float
in_handle Vector2
out_handle Vector2

bezier_track_interpolate(int, float)

Qualifiers: const

Returns the interpolated value at the given time (in seconds). The track_idx must be the index of a Bezier Track.

float bezier_track_interpolate(int track_idx, float time)

Parameters

track_idx int
time float

bezier_track_set_key_in_handle(int, int, Vector2, float)

Sets the in handle of the key identified by key_idx to value in_handle. The track_idx must be the index of a Bezier Track.

void bezier_track_set_key_in_handle(int track_idx, int key_idx, Vector2 in_handle, float balanced_value_time_ratio)

Parameters

track_idx int
key_idx int
in_handle Vector2
balanced_value_time_ratio float

bezier_track_set_key_out_handle(int, int, Vector2, float)

Sets the out handle of the key identified by key_idx to value out_handle. The track_idx must be the index of a Bezier Track.

void bezier_track_set_key_out_handle(int track_idx, int key_idx, Vector2 out_handle, float balanced_value_time_ratio)

Parameters

track_idx int
key_idx int
out_handle Vector2
balanced_value_time_ratio float

bezier_track_set_key_value(int, int, float)

Sets the value of the key identified by key_idx to the given value. The track_idx must be the index of a Bezier Track.

void bezier_track_set_key_value(int track_idx, int key_idx, float value)

Parameters

track_idx int
key_idx int
value float

blend_shape_track_insert_key(int, float, float)

Inserts a key in a given blend shape track. Returns the key index.

int blend_shape_track_insert_key(int track_idx, float time, float amount)

Parameters

track_idx int
time float
amount float

blend_shape_track_interpolate(int, float, bool)

Qualifiers: const

Returns the interpolated blend shape value at the given time (in seconds). The track_idx must be the index of a blend shape track.

float blend_shape_track_interpolate(int track_idx, float time_sec, bool backward)

Parameters

track_idx int
time_sec float
backward bool

clear

Clear the animation (clear all tracks and reset all).

void clear

compress(int, int, float)

Compress the animation and all its tracks in-place. This will make Animation.track_is_compressed return true once called on this Animation. Compressed tracks require less memory to be played, and are designed to be used for complex 3D animations (such as cutscenes) imported from external 3D software. Compression is lossy, but the difference is usually not noticeable in real world conditions.

Note: Compressed tracks have various limitations (such as not being editable from the editor), so only use compressed animations if you actually need them.

void compress(int page_size, int fps, float split_tolerance)

Parameters

page_size int
fps int
split_tolerance float

copy_track(int, Animation)

Adds a new track to to_animation that is a copy of the given track from this animation.

void copy_track(int track_idx, Animation to_animation)

Parameters

track_idx int
to_animation Animation

find_track(NodePath, int)

Qualifiers: const

Returns the index of the specified track. If the track is not found, return -1.

int find_track(NodePath path, int type)

Parameters

path NodePath
type int

get_marker_at_time(float)

Qualifiers: const

Returns the name of the marker located at the given time.

StringName get_marker_at_time(float time)

Parameters

time float

get_marker_color(StringName)

Qualifiers: const

Returns the given marker's color.

Color get_marker_color(StringName name)

Parameters

name StringName

get_marker_names

Qualifiers: const

Returns every marker in this Animation, sorted ascending by time.

PackedStringArray get_marker_names

get_marker_time(StringName)

Qualifiers: const

Returns the given marker's time.

float get_marker_time(StringName name)

Parameters

name StringName

get_next_marker(float)

Qualifiers: const

Returns the closest marker that comes after the given time. If no such marker exists, an empty string is returned.

StringName get_next_marker(float time)

Parameters

time float

get_prev_marker(float)

Qualifiers: const

Returns the closest marker that comes before the given time. If no such marker exists, an empty string is returned.

StringName get_prev_marker(float time)

Parameters

time float

get_track_count

Qualifiers: const

Returns the amount of tracks in the animation.

int get_track_count

has_marker(StringName)

Qualifiers: const

Returns true if this Animation contains a marker with the given name.

bool has_marker(StringName name)

Parameters

name StringName

method_track_get_name(int, int)

Qualifiers: const

Returns the method name of a method track.

StringName method_track_get_name(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

method_track_get_params(int, int)

Qualifiers: const

Returns the arguments values to be called on a method track for a given key in a given track.

Array method_track_get_params(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

optimize(float, float, int)

Optimize the animation and all its tracks in-place. This will preserve only as many keys as are necessary to keep the animation within the specified bounds.

void optimize(float allowed_velocity_err, float allowed_angular_err, int precision)

Parameters

allowed_velocity_err float
allowed_angular_err float
precision int

position_track_insert_key(int, float, Vector3)

Inserts a key in a given 3D position track. Returns the key index.

int position_track_insert_key(int track_idx, float time, Vector3 position)

Parameters

track_idx int
time float
position Vector3

position_track_interpolate(int, float, bool)

Qualifiers: const

Returns the interpolated position value at the given time (in seconds). The track_idx must be the index of a 3D position track.

Vector3 position_track_interpolate(int track_idx, float time_sec, bool backward)

Parameters

track_idx int
time_sec float
backward bool

remove_marker(StringName)

Removes the marker with the given name from this Animation.

void remove_marker(StringName name)

Parameters

name StringName

remove_track(int)

Removes a track by specifying the track index.

void remove_track(int track_idx)

Parameters

track_idx int

rotation_track_insert_key(int, float, Quaternion)

Inserts a key in a given 3D rotation track. Returns the key index.

int rotation_track_insert_key(int track_idx, float time, Quaternion rotation)

Parameters

track_idx int
time float
rotation Quaternion

rotation_track_interpolate(int, float, bool)

Qualifiers: const

Returns the interpolated rotation value at the given time (in seconds). The track_idx must be the index of a 3D rotation track.

Quaternion rotation_track_interpolate(int track_idx, float time_sec, bool backward)

Parameters

track_idx int
time_sec float
backward bool

scale_track_insert_key(int, float, Vector3)

Inserts a key in a given 3D scale track. Returns the key index.

int scale_track_insert_key(int track_idx, float time, Vector3 scale)

Parameters

track_idx int
time float
scale Vector3

scale_track_interpolate(int, float, bool)

Qualifiers: const

Returns the interpolated scale value at the given time (in seconds). The track_idx must be the index of a 3D scale track.

Vector3 scale_track_interpolate(int track_idx, float time_sec, bool backward)

Parameters

track_idx int
time_sec float
backward bool

set_marker_color(StringName, Color)

Sets the given marker's color.

void set_marker_color(StringName name, Color color)

Parameters

name StringName
color Color

track_find_key(int, float, int, bool, bool)

Qualifiers: const

Finds the key index by time in a given track. Optionally, only find it if the approx/exact time is given.

If limit is true, it does not return keys outside the animation range.

If backward is true, the direction is reversed in methods that rely on one directional processing.

For example, in case find_mode is Animation.FIND_MODE_NEAREST, if there is no key in the current position just after seeked, the first key found is retrieved by searching before the position, but if backward is true, the first key found is retrieved after the position.

int track_find_key(int track_idx, float time, int find_mode, bool limit, bool backward)

Parameters

track_idx int
time float
find_mode int
limit bool
backward bool

track_get_interpolation_loop_wrap(int)

Qualifiers: const

Returns true if the track at track_idx wraps the interpolation loop. New tracks wrap the interpolation loop by default.

bool track_get_interpolation_loop_wrap(int track_idx)

Parameters

track_idx int

track_get_interpolation_type(int)

Qualifiers: const

Returns the interpolation type of a given track.

int track_get_interpolation_type(int track_idx)

Parameters

track_idx int

track_get_key_count(int)

Qualifiers: const

Returns the number of keys in a given track.

int track_get_key_count(int track_idx)

Parameters

track_idx int

track_get_key_time(int, int)

Qualifiers: const

Returns the time at which the key is located.

float track_get_key_time(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

track_get_key_transition(int, int)

Qualifiers: const

Returns the transition curve (easing) for a specific key (see the built-in math function @GlobalScope.ease).

float track_get_key_transition(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

track_get_key_value(int, int)

Qualifiers: const

Returns the value of a given key in a given track.

Variant track_get_key_value(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

track_get_path(int)

Qualifiers: const

Gets the path of a track. For more information on the path format, see Animation.track_set_path.

NodePath track_get_path(int track_idx)

Parameters

track_idx int

track_get_type(int)

Qualifiers: const

Gets the type of a track.

int track_get_type(int track_idx)

Parameters

track_idx int

track_insert_key(int, float, Variant, float)

Inserts a generic key in a given track. Returns the key index.

int track_insert_key(int track_idx, float time, Variant key, float transition)

Parameters

track_idx int
time float
key Variant
transition float

track_is_compressed(int)

Qualifiers: const

Returns true if the track is compressed, false otherwise. See also Animation.compress.

bool track_is_compressed(int track_idx)

Parameters

track_idx int

track_is_enabled(int)

Qualifiers: const

Returns true if the track at index track_idx is enabled.

bool track_is_enabled(int track_idx)

Parameters

track_idx int

track_is_imported(int)

Qualifiers: const

Returns true if the given track is imported. Else, return false.

bool track_is_imported(int track_idx)

Parameters

track_idx int

track_move_down(int)

Moves a track down.

void track_move_down(int track_idx)

Parameters

track_idx int

track_move_to(int, int)

Changes the index position of track track_idx to the one defined in to_idx.

void track_move_to(int track_idx, int to_idx)

Parameters

track_idx int
to_idx int

track_move_up(int)

Moves a track up.

void track_move_up(int track_idx)

Parameters

track_idx int

track_remove_key(int, int)

Removes a key by index in a given track.

void track_remove_key(int track_idx, int key_idx)

Parameters

track_idx int
key_idx int

track_remove_key_at_time(int, float)

Removes a key at time in a given track.

void track_remove_key_at_time(int track_idx, float time)

Parameters

track_idx int
time float

track_set_enabled(int, bool)

Enables/disables the given track. Tracks are enabled by default.

void track_set_enabled(int track_idx, bool enabled)

Parameters

track_idx int
enabled bool

track_set_imported(int, bool)

Sets the given track as imported or not.

void track_set_imported(int track_idx, bool imported)

Parameters

track_idx int
imported bool

track_set_interpolation_loop_wrap(int, bool)

If true, the track at track_idx wraps the interpolation loop.

void track_set_interpolation_loop_wrap(int track_idx, bool interpolation)

Parameters

track_idx int
interpolation bool

track_set_interpolation_type(int, int)

Sets the interpolation type of a given track.

void track_set_interpolation_type(int track_idx, int interpolation)

Parameters

track_idx int
interpolation int

track_set_key_time(int, int, float)

Sets the time of an existing key.

void track_set_key_time(int track_idx, int key_idx, float time)

Parameters

track_idx int
key_idx int
time float

track_set_key_transition(int, int, float)

Sets the transition curve (easing) for a specific key (see the built-in math function @GlobalScope.ease).

void track_set_key_transition(int track_idx, int key_idx, float transition)

Parameters

track_idx int
key_idx int
transition float

track_set_key_value(int, int, Variant)

Sets the value of an existing key.

void track_set_key_value(int track_idx, int key, Variant value)

Parameters

track_idx int
key int
value Variant

track_set_path(int, NodePath)

Sets the path of a track. Paths must be valid scene-tree paths to a node and must be specified starting from the root_node that will reproduce the animation. Tracks that control properties or bones must append their name after the path, separated by ":".

For example, "character/skeleton:ankle" or "character/mesh:transform/local".

void track_set_path(int track_idx, NodePath path)

Parameters

track_idx int
path NodePath

track_swap(int, int)

Swaps the track track_idx's index position with the track with_idx.

void track_swap(int track_idx, int with_idx)

Parameters

track_idx int
with_idx int

value_track_get_update_mode(int)

Qualifiers: const

Returns the update mode of a value track.

int value_track_get_update_mode(int track_idx)

Parameters

track_idx int

value_track_interpolate(int, float, bool)

Qualifiers: const

Returns the interpolated value at the given time (in seconds). The track_idx must be the index of a value track.

A backward mainly affects the direction of key retrieval of the track with Animation.UPDATE_DISCRETE converted by AnimationMixer.ANIMATION_CALLBACK_MODE_DISCRETE_FORCE_CONTINUOUS to match the result with Animation.track_find_key.

Variant value_track_interpolate(int track_idx, float time_sec, bool backward)

Parameters

track_idx int
time_sec float
backward bool

value_track_set_update_mode(int, int)

Sets the update mode (see UpdateMode) of a value track.

void value_track_set_update_mode(int track_idx, int mode)

Parameters

track_idx int
mode int