Contains data used to animate everything in the engine.
    public class Animation : Resource

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.

[codeblock]

This creates an animation that makes the node “Enemy” move to the right by

100 pixels in 1 second.

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, 0.5, 100)

[/codeblock]

Animations are just data containers, and must be added to nodes such as an AnimationPlayer or AnimationTreePlayer to be played back.

Inheritance Chain

Constructors

    public Animation()

Signals

    "tracks_changed" ()

Properties

    public float Length { get; set; }

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.

    public bool Loop { get; set; }

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

    public float Step { get; set; }

The animation step value.

Methods

    public int AddTrack(TrackType type, int atPosition = -1)

Adds a track to the Animation.

    public string AnimationTrackGetKeyAnimation(int idx, int keyIdx)

    public int AnimationTrackInsertKey(int track, float time, string animation)

    public void AnimationTrackSetKeyAnimation(int idx, int keyIdx, string animation)

    public float AudioTrackGetKeyEndOffset(int idx, int keyIdx)

    public float AudioTrackGetKeyStartOffset(int idx, int keyIdx)

    public Resource AudioTrackGetKeyStream(int idx, int keyIdx)

    public int AudioTrackInsertKey(int track, float time, Resource stream, float startOffset = 0f, float endOffset = 0f)

    public void AudioTrackSetKeyEndOffset(int idx, int keyIdx, float offset)

    public void AudioTrackSetKeyStartOffset(int idx, int keyIdx, float offset)

    public void AudioTrackSetKeyStream(int idx, int keyIdx, Resource stream)

    public Vector2 BezierTrackGetKeyInHandle(int idx, int keyIdx)

    public Vector2 BezierTrackGetKeyOutHandle(int idx, int keyIdx)

    public float BezierTrackGetKeyValue(int idx, int keyIdx)

    public int BezierTrackInsertKey(int track, float time, float value, Vector2? inHandle = default(Vector2?), Vector2? outHandle = default(Vector2?))

    public float BezierTrackInterpolate(int track, float time)

    public void BezierTrackSetKeyInHandle(int idx, int keyIdx, Vector2 inHandle)

    public void BezierTrackSetKeyOutHandle(int idx, int keyIdx, Vector2 outHandle)

    public void BezierTrackSetKeyValue(int idx, int keyIdx, float value)

    public void Clear()

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

    public void CopyTrack(int track, Animation toAnimation)

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

    public int FindTrack(NodePath path)

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

    [Obsolete("GetLength is deprecated. Use the Length property instead.")]
    public float GetLength()

Getter for Length

    [Obsolete("GetStep is deprecated. Use the Step property instead.")]
    public float GetStep()

Getter for Step

    public int GetTrackCount()

Returns the amount of tracks in the animation.

    [Obsolete("HasLoop is deprecated. Use the Loop property instead.")]
    public bool HasLoop()

Getter for Loop

    public int[] MethodTrackGetKeyIndices(int idx, float timeSec, float delta)

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

    public string MethodTrackGetName(int idx, int keyIdx)

Returns the method name of a method track.

    public Godot.Collections.Array MethodTrackGetParams(int idx, int keyIdx)

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

    public void RemoveTrack(int idx)

Removes a track by specifying the track index.

    [Obsolete("SetLength is deprecated. Use the Length property instead.")]
    public void SetLength(float timeSec)

Setter for Length

    [Obsolete("SetLoop is deprecated. Use the Loop property instead.")]
    public void SetLoop(bool enabled)

Setter for Loop

    [Obsolete("SetStep is deprecated. Use the Step property instead.")]
    public void SetStep(float sizeSec)

Setter for Step

    public int TrackFindKey(int idx, float time, bool exact = false)

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

    public bool TrackGetInterpolationLoopWrap(int idx)

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

    public InterpolationType TrackGetInterpolationType(int idx)

Returns the interpolation type of a given track.

    public int TrackGetKeyCount(int idx)

Returns the amount of keys in a given track.

    public float TrackGetKeyTime(int idx, int keyIdx)

Returns the time at which the key is located.

    public float TrackGetKeyTransition(int idx, int keyIdx)

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

    public object TrackGetKeyValue(int idx, int keyIdx)

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

    public NodePath TrackGetPath(int idx)

Gets the path of a track. For more information on the path format, see TrackSetPath(int, Godot.NodePath).

    public TrackType TrackGetType(int idx)

Gets the type of a track.

    public void TrackInsertKey(int idx, float time, object key, float transition = 1f)

Insert a generic key in a given track.

    public bool TrackIsEnabled(int idx)

Returns true if the track at index idx is enabled.

    public bool TrackIsImported(int idx)

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

    public void TrackMoveDown(int idx)

Moves a track down.

    public void TrackMoveTo(int idx, int toIdx)

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

    public void TrackMoveUp(int idx)

Moves a track up.

    public void TrackRemoveKey(int idx, int keyIdx)

Removes a key by index in a given track.

    public void TrackRemoveKeyAtPosition(int idx, float position)

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

    public void TrackSetEnabled(int idx, bool enabled)

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

    public void TrackSetImported(int idx, bool imported)

Sets the given track as imported or not.

    public void TrackSetInterpolationLoopWrap(int idx, bool interpolation)

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

    public void TrackSetInterpolationType(int idx, InterpolationType interpolation)

Sets the interpolation type of a given track.

    public void TrackSetKeyTime(int idx, int keyIdx, float time)

Sets the time of an existing key.

    public void TrackSetKeyTransition(int idx, int keyIdx, float transition)

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

    public void TrackSetKeyValue(int idx, int key, object value)

Sets the value of an existing key.

    public void TrackSetPath(int 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".

    public void TrackSwap(int idx, int withIdx)

Swaps the track idx’s index position with the track withIdx.

    public int TransformTrackInsertKey(int idx, float time, Vector3 location, Quat rotation, Vector3 scale)

Insert a transform key for a transform track.

    public Godot.Collections.Array TransformTrackInterpolate(int idx, float timeSec)

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

    public int[] ValueTrackGetKeyIndices(int idx, float timeSec, float delta)

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

    public UpdateMode ValueTrackGetUpdateMode(int idx)

Returns the update mode of a value track.

    public void ValueTrackSetUpdateMode(int idx, UpdateMode mode)

Sets the update mode (UPDATE_*) of a value track.

Inner Types

InterpolationType

Name Value Description
Nearest 0 No interpolation (nearest value).
Linear 1 Linear interpolation.
Cubic 2 Cubic interpolation.

TrackType

Name Value Description
Value 0 Value tracks set values in node properties, but only those which can be Interpolated.
Transform 1 Transform tracks are used to change node local transforms or skeleton pose bones. Transitions are interpolated.
Method 2 Method tracks call functions with given arguments per key.
Bezier 3  
Audio 4  
Animation 5  

UpdateMode

Name Value Description
Continuous 0 Update between keyframes.
Discrete 1 Update at the keyframes and hold the value.
Trigger 2 Update at the keyframes.
Capture 3  
Tags: