Inheritance #

RefCounted

- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
Resource

- Animation
- AnimationLibrary
- AnimationNode (6)
- AnimationNodeStateMachinePlayback
- AnimationNodeStateMachineTransition
- AudioBusLayout
- AudioEffect (17)
- AudioStream (10)
- BitMap
- BoneMap
- ButtonGroup
- CameraAttributes (2)
- ColorPalette
- Compositor
- CompositorEffect
- CryptoKey
- Curve
- Curve2D
- Curve3D
- EditorNode3DGizmoPlugin
- EditorSettings
- Environment
- Font (3)
- GDExtension
- GLTFAccessor
- GLTFAnimation
- GLTFBufferView
- GLTFCamera
- GLTFDocument (1)
- GLTFDocumentExtension (1)
- GLTFLight
- GLTFMesh
- GLTFNode
- GLTFPhysicsBody
- GLTFPhysicsShape
- GLTFSkeleton
- GLTFSkin
- GLTFSpecGloss
- GLTFState (1)
- GLTFTexture
- GLTFTextureSampler
- Gradient
- Image
- ImporterMesh
- InputEvent (6)
- JSON
- LabelSettings
- LightmapGIData
- Material (9)
- Mesh (4)
- MeshLibrary
- MissingResource
- MultiMesh
- NavigationMesh
- NavigationMeshSourceGeometryData2D
- NavigationMeshSourceGeometryData3D
- NavigationPolygon
- Noise (1)
- Occluder3D (5)
- OccluderPolygon2D
- OggPacketSequence
- OpenXRAction
- OpenXRActionMap
- OpenXRActionSet
- OpenXRBindingModifier (2)
- OpenXRHapticBase (1)
- OpenXRIPBinding
- OpenXRInteractionProfile
- PackedDataContainer
- PackedScene
- PhysicsMaterial
- PolygonPathFinder
- RDShaderFile
- RDShaderSPIRV
- RichTextEffect
- SceneReplicationConfig
- Script (3)
- Shader (1)
- ShaderInclude
- Shape2D (8)
- Shape3D (9)
- Shortcut
- SkeletonModification2D (7)
- SkeletonModificationStack2D
- SkeletonProfile (1)
- Skin
- Sky
- SpriteFrames
- StyleBox (4)
- SyntaxHighlighter (2)
- Texture (3)
- Theme
- TileMapPattern
- TileSet
- TileSetSource (2)
- Translation (1)
- VideoStream (1)
- VideoStreamPlayback
- VisualShaderNode (62)
- VoxelGIData
- World2D
- World3D
- X509Certificate
Animation
Table of contents

Animation #

is_refcounted, is_instantiable, resource, core, not_builtin_classes

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

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.

GDScript

# 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

C#

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

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

Members #

var capture_included: bool = false#

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

var length: float = 1.0#

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 loop_mode = LOOP_NONE#

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 step: float = 0.0333333#

The animation step value.

Methods #

func add_marker(time: float) -> void#

Adds a marker to this Animation.

func add_track(at_position: int = -1) -> int#

Adds a track to the Animation.

const func animation_track_get_key_animation(key_idx: int) -> StringName#

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

func animation_track_insert_key(animation: StringName) -> int#

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

func animation_track_set_key_animation(animation: StringName) -> void#

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

const func audio_track_get_key_end_offset(key_idx: int) -> float#

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.

const func audio_track_get_key_start_offset(key_idx: int) -> float#

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.

const func audio_track_get_key_stream(key_idx: int) -> Resource#

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

func audio_track_insert_key(end_offset: float = 0) -> int#

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.

const func audio_track_is_use_blend(track_idx: int) -> bool#

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

func audio_track_set_key_end_offset(offset: float) -> void#

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.

func audio_track_set_key_start_offset(offset: float) -> void#

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.

func audio_track_set_key_stream(stream: Resource) -> void#

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

func audio_track_set_use_blend(enable: bool) -> void#

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

const func bezier_track_get_key_in_handle(key_idx: int) -> Vector2#

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

const func bezier_track_get_key_out_handle(key_idx: int) -> Vector2#

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

const func bezier_track_get_key_value(key_idx: int) -> float#

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

func bezier_track_insert_key(out_handle: Vector2 = Vector2(0, 0)) -> int#

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.

const func bezier_track_interpolate(time: float) -> float#

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

func bezier_track_set_key_in_handle(balanced_value_time_ratio: float = 1.0) -> void#

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.

func bezier_track_set_key_out_handle(balanced_value_time_ratio: float = 1.0) -> void#

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.

func bezier_track_set_key_value(value: float) -> void#

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.

func blend_shape_track_insert_key(amount: float) -> int#

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

const func blend_shape_track_interpolate(backward: bool = false) -> float#

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

func clear() -> void#

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

func compress(split_tolerance: float = 4.0) -> void#

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

func copy_track(to_animation: Animation) -> void#

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

const func find_track(type: int enumAnimation.TrackType) -> int#

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

const func get_marker_at_time(time: float) -> StringName#

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

const func get_marker_color(name: StringName) -> Color#

Returns the given marker's color.

const func get_marker_names() -> PackedStringArray#

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

const func get_marker_time(name: StringName) -> float#

Returns the given marker's time.

const func get_next_marker(time: float) -> StringName#

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

const func get_prev_marker(time: float) -> StringName#

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

const func get_track_count() -> int#

Returns the amount of tracks in the animation.

const func has_marker(name: StringName) -> bool#

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

const func method_track_get_name(key_idx: int) -> StringName#

Returns the method name of a method track.

const func method_track_get_params(key_idx: int) -> Array#

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

func optimize(precision: int = 3) -> void#

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.

func position_track_insert_key(position: Vector3) -> int#

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

const func position_track_interpolate(backward: bool = false) -> Vector3#

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

func remove_marker(name: StringName) -> void#

Removes the marker with the given name from this Animation.

func remove_track(track_idx: int) -> void#

Removes a track by specifying the track index.

func rotation_track_insert_key(rotation: Quaternion) -> int#

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

const func rotation_track_interpolate(backward: bool = false) -> Quaternion#

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

func scale_track_insert_key(scale: Vector3) -> int#

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

const func scale_track_interpolate(backward: bool = false) -> Vector3#

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

func set_marker_color(color: Color) -> void#

Sets the given marker's color.

const func track_find_key(backward: bool = false) -> int#

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 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.

const func track_get_interpolation_loop_wrap(track_idx: int) -> bool#

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

const func track_get_interpolation_type(track_idx: int) -> intAnimation.InterpolationType#

Returns the interpolation type of a given track.

const func track_get_key_count(track_idx: int) -> int#

Returns the number of keys in a given track.

const func track_get_key_time(key_idx: int) -> float#

Returns the time at which the key is located.

const func track_get_key_transition(key_idx: int) -> float#

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

const func track_get_key_value(key_idx: int) -> Variant#

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

const func track_get_path(track_idx: int) -> NodePath#

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

const func track_get_type(track_idx: int) -> intAnimation.TrackType#

Gets the type of a track.

func track_insert_key(transition: float = 1) -> int#

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

const func track_is_compressed(track_idx: int) -> bool#

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

const func track_is_enabled(track_idx: int) -> bool#

Returns true if the track at index track_idx is enabled.

const func track_is_imported(track_idx: int) -> bool#

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

func track_move_down(track_idx: int) -> void#

Moves a track down.

func track_move_to(to_idx: int) -> void#

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

func track_move_up(track_idx: int) -> void#

Moves a track up.

func track_remove_key(key_idx: int) -> void#

Removes a key by index in a given track.

func track_remove_key_at_time(time: float) -> void#

Removes a key at time in a given track.

func track_set_enabled(enabled: bool) -> void#

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

func track_set_imported(imported: bool) -> void#

Sets the given track as imported or not.

func track_set_interpolation_loop_wrap(interpolation: bool) -> void#

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

func track_set_interpolation_type(interpolation: int enumAnimation.InterpolationType) -> void#

Sets the interpolation type of a given track.

func track_set_key_time(time: float) -> void#

Sets the time of an existing key.

func track_set_key_transition(transition: float) -> void#

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

func track_set_key_value(value: Variant) -> void#

Sets the value of an existing key.

func track_set_path(path: NodePath) -> void#

Sets the path of a track. Paths must be valid scene-tree paths to a node and must be specified starting from the AnimationMixer.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".

func track_swap(with_idx: int) -> void#

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

const func value_track_get_update_mode(track_idx: int) -> intAnimation.UpdateMode#

Returns the update mode of a value track.

const func value_track_interpolate(backward: bool = false) -> Variant#

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 UPDATE_DISCRETE converted by AnimationMixer.ANIMATION_CALLBACK_MODE_DISCRETE_FORCE_CONTINUOUS to match the result with track_find_key.

func value_track_set_update_mode(mode: int enumAnimation.UpdateMode) -> void#

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

Annotations #

Constants #

const TYPE_VALUE = 0 enum TrackType#

Value tracks set values in node properties, but only those which can be interpolated. For 3D position/rotation/scale, using the dedicated TYPE_POSITION_3D, TYPE_ROTATION_3D and TYPE_SCALE_3D track types instead of TYPE_VALUE is recommended for performance reasons.

const TYPE_POSITION_3D = 1 enum TrackType#

3D position track (values are stored in Vector3s).

const TYPE_ROTATION_3D = 2 enum TrackType#

3D rotation track (values are stored in Quaternions).

const TYPE_SCALE_3D = 3 enum TrackType#

3D scale track (values are stored in Vector3s).

const TYPE_BLEND_SHAPE = 4 enum TrackType#

Blend shape track.

const TYPE_METHOD = 5 enum TrackType#

Method tracks call functions with given arguments per key.

const TYPE_BEZIER = 6 enum TrackType#

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).

const TYPE_AUDIO = 7 enum TrackType#

Audio tracks are used to play an audio stream with either type of AudioStreamPlayer. The stream can be trimmed and previewed in the animation.

const TYPE_ANIMATION = 8 enum TrackType#

Animation tracks play animations in other AnimationPlayer nodes.

const INTERPOLATION_NEAREST = 0 enum InterpolationType#

No interpolation (nearest value).

const INTERPOLATION_LINEAR = 1 enum InterpolationType#

Linear interpolation.

const INTERPOLATION_CUBIC = 2 enum InterpolationType#

Cubic interpolation. This looks smoother than linear interpolation, but is more expensive to interpolate. Stick to INTERPOLATION_LINEAR for complex 3D animations imported from external software, even if it requires using a higher animation framerate in return.

const INTERPOLATION_LINEAR_ANGLE = 3 enum InterpolationType#

Linear interpolation with shortest path rotation.

Note: The result value is always normalized and may not match the key value.

const INTERPOLATION_CUBIC_ANGLE = 4 enum InterpolationType#

Cubic interpolation with shortest path rotation.

Note: The result value is always normalized and may not match the key value.

const UPDATE_CONTINUOUS = 0 enum UpdateMode#

Update between keyframes and hold the value.

const UPDATE_DISCRETE = 1 enum UpdateMode#

Update at the keyframes.

const UPDATE_CAPTURE = 2 enum UpdateMode#

Same as UPDATE_CONTINUOUS but works as a flag to capture the value of the current object and perform interpolation in some methods. See also AnimationMixer.capture, AnimationPlayer.playback_auto_capture, and AnimationPlayer.play_with_capture.

const LOOP_NONE = 0 enum LoopMode#

At both ends of the animation, the animation will stop playing.

const LOOP_LINEAR = 1 enum LoopMode#

At both ends of the animation, the animation will be repeated without changing the playback direction.

const LOOP_PINGPONG = 2 enum LoopMode#

Repeats playback and reverse playback at both ends of the animation.

const LOOPED_FLAG_NONE = 0 enum LoopedFlag#

This flag indicates that the animation proceeds without any looping.

const LOOPED_FLAG_END = 1 enum LoopedFlag#

This flag indicates that the animation has reached the end of the animation and just after loop processed.

const LOOPED_FLAG_START = 2 enum LoopedFlag#

This flag indicates that the animation has reached the start of the animation and just after loop processed.

const FIND_MODE_NEAREST = 0 enum FindMode#

Finds the nearest time key.

const FIND_MODE_APPROX = 1 enum FindMode#

Finds only the key with approximating the time.

const FIND_MODE_EXACT = 2 enum FindMode#

Finds only the key with matching the time.

Constructors #

Enums #

TrackType#

enum TrackType { TYPE_VALUE = 0, TYPE_POSITION_3D = 1, TYPE_ROTATION_3D = 2, TYPE_SCALE_3D = 3, TYPE_BLEND_SHAPE = 4, TYPE_METHOD = 5, TYPE_BEZIER = 6, TYPE_AUDIO = 7, TYPE_ANIMATION = 8, }

InterpolationType#

enum InterpolationType { INTERPOLATION_NEAREST = 0, INTERPOLATION_LINEAR = 1, INTERPOLATION_CUBIC = 2, INTERPOLATION_LINEAR_ANGLE = 3, INTERPOLATION_CUBIC_ANGLE = 4, }

UpdateMode#

enum UpdateMode { UPDATE_CONTINUOUS = 0, UPDATE_DISCRETE = 1, UPDATE_CAPTURE = 2, }

LoopMode#

enum LoopMode { LOOP_NONE = 0, LOOP_LINEAR = 1, LOOP_PINGPONG = 2, }

LoopedFlag#

enum LoopedFlag { LOOPED_FLAG_NONE = 0, LOOPED_FLAG_END = 1, LOOPED_FLAG_START = 2, }

FindMode#

enum FindMode { FIND_MODE_NEAREST = 0, FIND_MODE_APPROX = 1, FIND_MODE_EXACT = 2, }

Operators #

Signals #

Theme Items #

Tutorials #