Animation

    Contains data used to animate everything in the engine.

    An Animation resource contains data used to animate everything 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.

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

    Tutorials

    Methods

    • tracks_changed ( )

    Emitted when there’s a change in the list of tracks, e.g. tracks are added, moved or have changed paths.

    Enumerations

    enum TrackType:

    • TYPE_VALUE = 0 —- Value tracks set values in node properties, but only those which can be Interpolated.

    • TYPE_TRANSFORM = 1 —- Transform tracks are used to change node local transforms or skeleton pose bones. Transitions are interpolated.

    • TYPE_METHOD = 2 —- Method tracks call functions with given arguments per key.

    • TYPE_BEZIER = 3 —- Bezier tracks are used to interpolate a value using custom curves. They can also be used to animate sub-properties of vectors and colors (e.g. alpha value of a Color).

    • TYPE_AUDIO = 4 —- Audio tracks are used to play an audio stream with either type of . The stream can be trimmed and previewed in the animation.

    • TYPE_ANIMATION = 5 —- Animation tracks play animations in other AnimationPlayer nodes.


    enum InterpolationType:

    • INTERPOLATION_NEAREST = 0 —- No interpolation (nearest value).

    • INTERPOLATION_LINEAR = 1 —- Linear interpolation.

    • INTERPOLATION_CUBIC = 2 —- Cubic interpolation.


    enum UpdateMode:

    • UPDATE_CONTINUOUS = 0 —- Update between keyframes.

    • UPDATE_DISCRETE = 1 —- Update at the keyframes and hold the value.

    • UPDATE_TRIGGER = 2 —- Update at the keyframes.

    • UPDATE_CAPTURE = 3 —- Same as linear interpolation, but also interpolates from the current value (i.e. dynamically at runtime) if the first key isn’t at 0 seconds.

    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.


    • loop

    A flag indicating that the animation must loop. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.


    The animation step value.

    Method Descriptions

    • int add_track ( type, int at_position=-1 )

    Adds a track to the Animation.


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


    • animation_track_insert_key ( int track_idx, time, String animation )

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


    • void animation_track_set_key_animation ( track_idx, int key_idx, animation )

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


    • float audio_track_get_key_end_offset ( track_idx, int key_idx ) 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.


    • audio_track_get_key_start_offset ( int track_idx, key_idx ) 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.


    • Resource audio_track_get_key_stream ( track_idx, int key_idx ) const

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


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

    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 resource to play. start_offset is the number of seconds cut off at the beginning of the audio stream, while is at the ending.


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

    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_start_offset ( track_idx, int key_idx, offset )

    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_stream ( int track_idx, key_idx, Resource stream )

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


    • bezier_track_get_key_in_handle ( int track_idx, key_idx ) 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_out_handle ( track_idx, int key_idx ) const

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


    • bezier_track_get_key_value ( int track_idx, key_idx ) const

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


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

    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.


    • float bezier_track_interpolate ( track_idx, float time ) const

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


    • void bezier_track_set_key_in_handle ( track_idx, int key_idx, in_handle )

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


    • void bezier_track_set_key_out_handle ( int track_idx, key_idx, Vector2 out_handle )

    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_value ( track_idx, int key_idx, value )

    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 clear ( )

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


    • void copy_track ( int track_idx, to_animation )

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


    • int find_track ( path ) const

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


    • int get_track_count ( ) const

    Returns the amount of tracks in the animation.


    • method_track_get_key_indices ( int track_idx, time_sec, float delta ) const

    Returns all the key indices of a method track, given a position and delta time.


    • method_track_get_name ( int track_idx, key_idx ) const

    Returns the method name of a method track.


    • Array method_track_get_params ( track_idx, int key_idx ) const

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


    • void remove_track ( track_idx )

    Removes a track by specifying the track index.


    • int track_find_key ( track_idx, float time, exact=false ) const

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


    • bool track_get_interpolation_loop_wrap ( track_idx ) const

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


    Returns the interpolation type of a given track.


    • int track_get_key_count ( track_idx ) const

    Returns the amount of keys in a given track.


    • float track_get_key_time ( track_idx, int key_idx ) const

    Returns the time at which the key is located.


    • track_get_key_transition ( int track_idx, key_idx ) const

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


    • track_get_key_value ( int track_idx, key_idx ) const

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


    • NodePath track_get_path ( track_idx ) const

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


    • track_get_type ( int track_idx ) const

    Gets the type of a track.


    • void track_insert_key ( track_idx, float time, key, float transition=1 )

    Insert a generic key in a given track.


    • track_is_enabled ( int track_idx ) const

    Returns true if the track at index idx is enabled.


    • track_is_imported ( int track_idx ) const

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


    • void track_move_down ( track_idx )

    Moves a track down.


    • void track_move_to ( int track_idx, to_idx )

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


    • void track_move_up ( int track_idx )

    Moves a track up.


    • void track_remove_key ( track_idx, int key_idx )

    Removes a key by index in a given track.


    • void track_remove_key_at_position ( track_idx, float position )

    Removes a key by position (seconds) in a given track.


    • void track_set_enabled ( track_idx, bool enabled )

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


    • void track_set_imported ( track_idx, bool imported )

    Sets the given track as imported or not.


    • void track_set_interpolation_loop_wrap ( track_idx, bool interpolation )

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


    Sets the interpolation type of a given track.


    • void track_set_key_time ( track_idx, int key_idx, time )

    Sets the time of an existing key.


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

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


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

    Sets the value of an existing key.


    • void track_set_path ( track_idx, NodePath path )

    Sets the path of a track. Paths must be valid scene-tree paths to a node and must be specified starting from the parent node of the 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_swap ( track_idx, int with_idx )

    Swaps the track idx‘s index position with the track with_idx.


    • transform_track_insert_key ( int track_idx, time, Vector3 location, rotation, Vector3 scale )

    Insert a transform key for a transform track.


    • transform_track_interpolate ( int track_idx, time_sec ) const

    Returns the interpolated value of a transform track at a given time (in seconds). An array consisting of 3 elements: position (Vector3), rotation () and scale (Vector3).


    • value_track_get_key_indices ( int track_idx, time_sec, float delta ) const

    Returns all the key indices of a value track, given a position and delta time.


    • value_track_get_update_mode ( int track_idx ) const

    Returns the update mode of a value track.


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


    • void value_track_set_update_mode ( track_idx, UpdateMode mode )

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