Table of Contents

Class Animation

Namespace
Godot
Assembly
GodotSharp.dll

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 = new Animation();
  int trackIndex = animation.AddTrack(Animation.TrackType.Value);
  animation.TrackSetPath(trackIndex, "Enemy:position:x");
  animation.TrackInsertKey(trackIndex, 0.0f, 0);
  animation.TrackInsertKey(trackIndex, 2.0f, 100);
  animation.Length = 2.0f;

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 Animation.TrackType to see available types.

Note: For 3D position/rotation/scale, using the dedicated Position3D, Rotation3D and Scale3D track types instead of Value is recommended for performance reasons.

public class Animation : Resource, IDisposable
Inheritance
Animation
Implements
Inherited Members

Constructors

Animation()

public Animation()

Properties

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.

public float Length { get; set; }

Property Value

float

LoopMode

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.

public Animation.LoopModeEnum LoopMode { get; set; }

Property Value

Animation.LoopModeEnum

Step

The animation step value.

public float Step { get; set; }

Property Value

float

Methods

AddTrack(TrackType, int)

Adds a track to the Animation.

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

Parameters

type Animation.TrackType
atPosition int

Returns

int

AnimationTrackGetKeyAnimation(int, int)

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

public StringName AnimationTrackGetKeyAnimation(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

StringName

AnimationTrackInsertKey(int, double, StringName)

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

public int AnimationTrackInsertKey(int trackIdx, double time, StringName animation)

Parameters

trackIdx int
time double
animation StringName

Returns

int

AnimationTrackSetKeyAnimation(int, int, StringName)

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

public void AnimationTrackSetKeyAnimation(int trackIdx, int keyIdx, StringName animation)

Parameters

trackIdx int
keyIdx int
animation StringName

AudioTrackGetKeyEndOffset(int, int)

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

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

public float AudioTrackGetKeyEndOffset(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

float

AudioTrackGetKeyStartOffset(int, int)

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

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

public float AudioTrackGetKeyStartOffset(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

float

AudioTrackGetKeyStream(int, int)

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

public Resource AudioTrackGetKeyStream(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

Resource

AudioTrackInsertKey(int, double, Resource, float, float)

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

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

public int AudioTrackInsertKey(int trackIdx, double time, Resource stream, float startOffset = 0, float endOffset = 0)

Parameters

trackIdx int
time double
stream Resource
startOffset float
endOffset float

Returns

int

AudioTrackIsUseBlend(int)

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

public bool AudioTrackIsUseBlend(int trackIdx)

Parameters

trackIdx int

Returns

bool

AudioTrackSetKeyEndOffset(int, int, float)

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

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

Parameters

trackIdx int
keyIdx int
offset float

AudioTrackSetKeyStartOffset(int, int, float)

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

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

Parameters

trackIdx int
keyIdx int
offset float

AudioTrackSetKeyStream(int, int, Resource)

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

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

Parameters

trackIdx int
keyIdx int
stream Resource

AudioTrackSetUseBlend(int, bool)

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

public void AudioTrackSetUseBlend(int trackIdx, bool enable)

Parameters

trackIdx int
enable bool

BezierTrackGetKeyInHandle(int, int)

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

public Vector2 BezierTrackGetKeyInHandle(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

Vector2

BezierTrackGetKeyOutHandle(int, int)

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

public Vector2 BezierTrackGetKeyOutHandle(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

Vector2

BezierTrackGetKeyValue(int, int)

Returns the value of the key identified by keyIdx. The trackIdx must be the index of a Bezier Track.

public float BezierTrackGetKeyValue(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

float

BezierTrackInsertKey(int, double, float, Vector2?, Vector2?)

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

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

public int BezierTrackInsertKey(int trackIdx, double time, float value, Vector2? inHandle = null, Vector2? outHandle = null)

Parameters

trackIdx int
time double
value float
inHandle Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

outHandle Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

Returns

int

BezierTrackInterpolate(int, double)

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

public float BezierTrackInterpolate(int trackIdx, double time)

Parameters

trackIdx int
time double

Returns

float

BezierTrackSetKeyInHandle(int, int, Vector2, float)

Sets the in handle of the key identified by keyIdx to value inHandle. The trackIdx must be the index of a Bezier Track.

public void BezierTrackSetKeyInHandle(int trackIdx, int keyIdx, Vector2 inHandle, float balancedValueTimeRatio = 1)

Parameters

trackIdx int
keyIdx int
inHandle Vector2
balancedValueTimeRatio float

BezierTrackSetKeyOutHandle(int, int, Vector2, float)

Sets the out handle of the key identified by keyIdx to value outHandle. The trackIdx must be the index of a Bezier Track.

public void BezierTrackSetKeyOutHandle(int trackIdx, int keyIdx, Vector2 outHandle, float balancedValueTimeRatio = 1)

Parameters

trackIdx int
keyIdx int
outHandle Vector2
balancedValueTimeRatio float

BezierTrackSetKeyValue(int, int, float)

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

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

Parameters

trackIdx int
keyIdx int
value float

BlendShapeTrackInsertKey(int, double, float)

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

public int BlendShapeTrackInsertKey(int trackIdx, double time, float amount)

Parameters

trackIdx int
time double
amount float

Returns

int

BlendShapeTrackInterpolate(int, double)

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

public float BlendShapeTrackInterpolate(int trackIdx, double timeSec)

Parameters

trackIdx int
timeSec double

Returns

float

Clear()

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

public void Clear()

Compress(uint, uint, float)

Compress the animation and all its tracks in-place. This will make TrackIsCompressed(int) 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.

public void Compress(uint pageSize = 8192, uint fps = 120, float splitTolerance = 4)

Parameters

pageSize uint
fps uint
splitTolerance float

CopyTrack(int, Animation)

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

public void CopyTrack(int trackIdx, Animation toAnimation)

Parameters

trackIdx int
toAnimation Animation

FindTrack(NodePath, TrackType)

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

public int FindTrack(NodePath path, Animation.TrackType type)

Parameters

path NodePath
type Animation.TrackType

Returns

int

GetTrackCount()

Returns the amount of tracks in the animation.

public int GetTrackCount()

Returns

int

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

MethodTrackGetName(int, int)

Returns the method name of a method track.

public StringName MethodTrackGetName(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

StringName

MethodTrackGetParams(int, int)

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

public Array MethodTrackGetParams(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

Array

PositionTrackInsertKey(int, double, Vector3)

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

public int PositionTrackInsertKey(int trackIdx, double time, Vector3 position)

Parameters

trackIdx int
time double
position Vector3

Returns

int

PositionTrackInterpolate(int, double)

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

public Vector3 PositionTrackInterpolate(int trackIdx, double timeSec)

Parameters

trackIdx int
timeSec double

Returns

Vector3

RemoveTrack(int)

Removes a track by specifying the track index.

public void RemoveTrack(int trackIdx)

Parameters

trackIdx int

RotationTrackInsertKey(int, double, Quaternion)

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

public int RotationTrackInsertKey(int trackIdx, double time, Quaternion rotation)

Parameters

trackIdx int
time double
rotation Quaternion

Returns

int

RotationTrackInterpolate(int, double)

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

public Quaternion RotationTrackInterpolate(int trackIdx, double timeSec)

Parameters

trackIdx int
timeSec double

Returns

Quaternion

ScaleTrackInsertKey(int, double, Vector3)

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

public int ScaleTrackInsertKey(int trackIdx, double time, Vector3 scale)

Parameters

trackIdx int
time double
scale Vector3

Returns

int

ScaleTrackInterpolate(int, double)

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

public Vector3 ScaleTrackInterpolate(int trackIdx, double timeSec)

Parameters

trackIdx int
timeSec double

Returns

Vector3

TrackFindKey(int, double, FindMode)

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

public int TrackFindKey(int trackIdx, double time, Animation.FindMode findMode = FindMode.Nearest)

Parameters

trackIdx int
time double
findMode Animation.FindMode

Returns

int

TrackGetInterpolationLoopWrap(int)

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

public bool TrackGetInterpolationLoopWrap(int trackIdx)

Parameters

trackIdx int

Returns

bool

TrackGetInterpolationType(int)

Returns the interpolation type of a given track.

public Animation.InterpolationType TrackGetInterpolationType(int trackIdx)

Parameters

trackIdx int

Returns

Animation.InterpolationType

TrackGetKeyCount(int)

Returns the number of keys in a given track.

public int TrackGetKeyCount(int trackIdx)

Parameters

trackIdx int

Returns

int

TrackGetKeyTime(int, int)

Returns the time at which the key is located.

public double TrackGetKeyTime(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

double

TrackGetKeyTransition(int, int)

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

public float TrackGetKeyTransition(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

float

TrackGetKeyValue(int, int)

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

public Variant TrackGetKeyValue(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

Returns

Variant

TrackGetPath(int)

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

public NodePath TrackGetPath(int trackIdx)

Parameters

trackIdx int

Returns

NodePath

TrackGetType(int)

Gets the type of a track.

public Animation.TrackType TrackGetType(int trackIdx)

Parameters

trackIdx int

Returns

Animation.TrackType

TrackInsertKey(int, double, Variant, float)

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

public int TrackInsertKey(int trackIdx, double time, Variant key, float transition = 1)

Parameters

trackIdx int
time double
key Variant
transition float

Returns

int

TrackIsCompressed(int)

Returns true if the track is compressed, false otherwise. See also Compress(uint, uint, float).

public bool TrackIsCompressed(int trackIdx)

Parameters

trackIdx int

Returns

bool

TrackIsEnabled(int)

Returns true if the track at index trackIdx is enabled.

public bool TrackIsEnabled(int trackIdx)

Parameters

trackIdx int

Returns

bool

TrackIsImported(int)

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

public bool TrackIsImported(int trackIdx)

Parameters

trackIdx int

Returns

bool

TrackMoveDown(int)

Moves a track down.

public void TrackMoveDown(int trackIdx)

Parameters

trackIdx int

TrackMoveTo(int, int)

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

public void TrackMoveTo(int trackIdx, int toIdx)

Parameters

trackIdx int
toIdx int

TrackMoveUp(int)

Moves a track up.

public void TrackMoveUp(int trackIdx)

Parameters

trackIdx int

TrackRemoveKey(int, int)

Removes a key by index in a given track.

public void TrackRemoveKey(int trackIdx, int keyIdx)

Parameters

trackIdx int
keyIdx int

TrackRemoveKeyAtTime(int, double)

Removes a key at time in a given track.

public void TrackRemoveKeyAtTime(int trackIdx, double time)

Parameters

trackIdx int
time double

TrackSetEnabled(int, bool)

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

public void TrackSetEnabled(int trackIdx, bool enabled)

Parameters

trackIdx int
enabled bool

TrackSetImported(int, bool)

Sets the given track as imported or not.

public void TrackSetImported(int trackIdx, bool imported)

Parameters

trackIdx int
imported bool

TrackSetInterpolationLoopWrap(int, bool)

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

public void TrackSetInterpolationLoopWrap(int trackIdx, bool interpolation)

Parameters

trackIdx int
interpolation bool

TrackSetInterpolationType(int, InterpolationType)

Sets the interpolation type of a given track.

public void TrackSetInterpolationType(int trackIdx, Animation.InterpolationType interpolation)

Parameters

trackIdx int
interpolation Animation.InterpolationType

TrackSetKeyTime(int, int, double)

Sets the time of an existing key.

public void TrackSetKeyTime(int trackIdx, int keyIdx, double time)

Parameters

trackIdx int
keyIdx int
time double

TrackSetKeyTransition(int, int, float)

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

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

Parameters

trackIdx int
keyIdx int
transition float

TrackSetKeyValue(int, int, Variant)

Sets the value of an existing key.

public void TrackSetKeyValue(int trackIdx, int key, Variant value)

Parameters

trackIdx int
key int
value Variant

TrackSetPath(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 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 TrackSetPath(int trackIdx, NodePath path)

Parameters

trackIdx int
path NodePath

TrackSwap(int, int)

Swaps the track trackIdx's index position with the track withIdx.

public void TrackSwap(int trackIdx, int withIdx)

Parameters

trackIdx int
withIdx int

ValueTrackGetUpdateMode(int)

Returns the update mode of a value track.

public Animation.UpdateMode ValueTrackGetUpdateMode(int trackIdx)

Parameters

trackIdx int

Returns

Animation.UpdateMode

ValueTrackInterpolate(int, double)

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

public Variant ValueTrackInterpolate(int trackIdx, double timeSec)

Parameters

trackIdx int
timeSec double

Returns

Variant

ValueTrackSetUpdateMode(int, UpdateMode)

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

public void ValueTrackSetUpdateMode(int trackIdx, Animation.UpdateMode mode)

Parameters

trackIdx int
mode Animation.UpdateMode