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
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
Step
The animation step value.
public float Step { get; set; }
Property Value
Methods
AddTrack(TrackType, int)
Adds a track to the Animation.
public int AddTrack(Animation.TrackType type, int atPosition = -1)
Parameters
Returns
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
Returns
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
inttime
doubleanimation
StringName
Returns
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
intkeyIdx
intanimation
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
Returns
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
Returns
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
Returns
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
Returns
AudioTrackIsUseBlend(int)
Returns true
if the track at trackIdx
will be blended with other animations.
public bool AudioTrackIsUseBlend(int trackIdx)
Parameters
trackIdx
int
Returns
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
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
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
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
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
Returns
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
Returns
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
Returns
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
inttime
doublevalue
floatinHandle
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
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
Returns
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
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
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
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
Returns
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
Returns
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
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
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
Returns
GetTrackCount()
Returns the amount of tracks in the animation.
public int GetTrackCount()
Returns
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
MethodTrackGetName(int, int)
Returns the method name of a method track.
public StringName MethodTrackGetName(int trackIdx, int keyIdx)
Parameters
Returns
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
Returns
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
Returns
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
Returns
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
inttime
doublerotation
Quaternion
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
TrackGetInterpolationType(int)
Returns the interpolation type of a given track.
public Animation.InterpolationType TrackGetInterpolationType(int trackIdx)
Parameters
trackIdx
int
Returns
TrackGetKeyCount(int)
Returns the number of keys in a given track.
public int TrackGetKeyCount(int trackIdx)
Parameters
trackIdx
int
Returns
TrackGetKeyTime(int, int)
Returns the time at which the key is located.
public double TrackGetKeyTime(int trackIdx, int keyIdx)
Parameters
Returns
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
Returns
TrackGetKeyValue(int, int)
Returns the value of a given key in a given track.
public Variant TrackGetKeyValue(int trackIdx, int keyIdx)
Parameters
Returns
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
TrackGetType(int)
Gets the type of a track.
public Animation.TrackType TrackGetType(int trackIdx)
Parameters
trackIdx
int
Returns
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
Returns
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
TrackIsEnabled(int)
Returns true
if the track at index trackIdx
is enabled.
public bool TrackIsEnabled(int trackIdx)
Parameters
trackIdx
int
Returns
TrackIsImported(int)
Returns true
if the given track is imported. Else, return false
.
public bool TrackIsImported(int trackIdx)
Parameters
trackIdx
int
Returns
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
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
TrackRemoveKeyAtTime(int, double)
Removes a key at time
in a given track.
public void TrackRemoveKeyAtTime(int trackIdx, double time)
Parameters
TrackSetEnabled(int, bool)
Enables/disables the given track. Tracks are enabled by default.
public void TrackSetEnabled(int trackIdx, bool enabled)
Parameters
TrackSetImported(int, bool)
Sets the given track as imported or not.
public void TrackSetImported(int trackIdx, bool imported)
Parameters
TrackSetInterpolationLoopWrap(int, bool)
If true
, the track at trackIdx
wraps the interpolation loop.
public void TrackSetInterpolationLoopWrap(int trackIdx, bool interpolation)
Parameters
TrackSetInterpolationType(int, InterpolationType)
Sets the interpolation type of a given track.
public void TrackSetInterpolationType(int trackIdx, Animation.InterpolationType interpolation)
Parameters
trackIdx
intinterpolation
Animation.InterpolationType
TrackSetKeyTime(int, int, double)
Sets the time of an existing key.
public void TrackSetKeyTime(int trackIdx, int keyIdx, double time)
Parameters
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
TrackSetKeyValue(int, int, Variant)
Sets the value of an existing key.
public void TrackSetKeyValue(int trackIdx, int key, Variant value)
Parameters
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
TrackSwap(int, int)
Swaps the track trackIdx
's index position with the track withIdx
.
public void TrackSwap(int trackIdx, int withIdx)
Parameters
ValueTrackGetUpdateMode(int)
Returns the update mode of a value track.
public Animation.UpdateMode ValueTrackGetUpdateMode(int trackIdx)
Parameters
trackIdx
int
Returns
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
Returns
ValueTrackSetUpdateMode(int, UpdateMode)
Sets the update mode (see Animation.UpdateMode) of a value track.
public void ValueTrackSetUpdateMode(int trackIdx, Animation.UpdateMode mode)
Parameters
trackIdx
intmode
Animation.UpdateMode