Animation

Inherits: Resource < Reference < Object

Category: Core

Brief Description

Contains data used to animate everything in the engine.

Properties

floatlength
boolloop
floatstep

Methods

intadd_track ( TrackType type, int at_position=-1 )
Stringanimation_track_get_key_animation ( int idx, int key_idx ) const
intanimation_track_insert_key ( int track, float time, String animation )
voidanimation_track_set_key_animation ( int idx, int key_idx, String animation )
floataudio_track_get_key_end_offset ( int idx, int key_idx ) const
floataudio_track_get_key_start_offset ( int idx, int key_idx ) const
Resourceaudio_track_get_key_stream ( int idx, int key_idx ) const
intaudio_track_insert_key ( int track, float time, Resource stream, float start_offset=0, float end_offset=0 )
voidaudio_track_set_key_end_offset ( int idx, int key_idx, float offset )
voidaudio_track_set_key_start_offset ( int idx, int key_idx, float offset )
voidaudio_track_set_key_stream ( int idx, int key_idx, Resource stream )
Vector2bezier_track_get_key_in_handle ( int idx, int key_idx ) const
Vector2bezier_track_get_key_out_handle ( int idx, int key_idx ) const
floatbezier_track_get_key_value ( int idx, int key_idx ) const
intbezier_track_insert_key ( int track, float time, float value, Vector2 in_handle=Vector2( 0, 0 ), Vector2 out_handle=Vector2( 0, 0 ) )
floatbezier_track_interpolate ( int track, float time ) const
voidbezier_track_set_key_in_handle ( int idx, int key_idx, Vector2 in_handle )
voidbezier_track_set_key_out_handle ( int idx, int key_idx, Vector2 out_handle )
voidbezier_track_set_key_value ( int idx, int key_idx, float value )
voidclear ( )
voidcopy_track ( int track, Animation to_animation )
intfind_track ( NodePath path ) const
intget_track_count ( ) const
PoolIntArraymethod_track_get_key_indices ( int idx, float time_sec, float delta ) const
Stringmethod_track_get_name ( int idx, int key_idx ) const
Arraymethod_track_get_params ( int idx, int key_idx ) const
voidremove_track ( int idx )
inttrack_find_key ( int idx, float time, bool exact=false ) const
booltrack_get_interpolation_loop_wrap ( int idx ) const
InterpolationTypetrack_get_interpolation_type ( int idx ) const
inttrack_get_key_count ( int idx ) const
floattrack_get_key_time ( int idx, int key_idx ) const
floattrack_get_key_transition ( int idx, int key_idx ) const
Varianttrack_get_key_value ( int idx, int key_idx ) const
NodePathtrack_get_path ( int idx ) const
TrackTypetrack_get_type ( int idx ) const
voidtrack_insert_key ( int idx, float time, Variant key, float transition=1 )
booltrack_is_enabled ( int idx ) const
booltrack_is_imported ( int idx ) const
voidtrack_move_down ( int idx )
voidtrack_move_up ( int idx )
voidtrack_remove_key ( int idx, int key_idx )
voidtrack_remove_key_at_position ( int idx, float position )
voidtrack_set_enabled ( int idx, bool enabled )
voidtrack_set_imported ( int idx, bool imported )
voidtrack_set_interpolation_loop_wrap ( int idx, bool interpolation )
voidtrack_set_interpolation_type ( int idx, InterpolationType interpolation )
voidtrack_set_key_transition ( int idx, int key_idx, float transition )
voidtrack_set_key_value ( int idx, int key, Variant value )
voidtrack_set_path ( int idx, NodePath path )
voidtrack_swap ( int idx, int with_idx )
inttransform_track_insert_key ( int idx, float time, Vector3 location, Quat rotation, Vector3 scale )
Arraytransform_track_interpolate ( int idx, float time_sec ) const
PoolIntArrayvalue_track_get_key_indices ( int idx, float time_sec, float delta ) const
UpdateModevalue_track_get_update_mode ( int idx ) const
voidvalue_track_set_update_mode ( int idx, UpdateMode mode )

Signals

  • tracks_changed ( )

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
  • TYPE_AUDIO = 4
  • TYPE_ANIMATION = 5

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

Description

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.

  1. # This creates an animation that makes the node "Enemy" move to the right by
  2. # 100 pixels in 1 second.
  3. var animation = Animation.new()
  4. var track_index = animation.add_track(Animation.TYPE_VALUE)
  5. animation.track_set_path(track_index, "Enemy:position.x")
  6. animation.track_insert_key(track_index, 0.0, 0)
  7. animation.track_insert_key(track_index, 0.5, 100)

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

Tutorials

Property Descriptions

Setterset_length(value)
Getterget_length()

The total length of the animation (in seconds). Note that length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.


Setterset_loop(value)
Getterhas_loop()

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.


Setterset_step(value)
Getterget_step()

The animation step value.

Method Descriptions

Add a track to the Animation. The track type must be specified as any of the values in the TYPE_* enumeration.


  • String animation_track_get_key_animation ( int idx, int key_idx ) const


  • void animation_track_set_key_animation ( int idx, int key_idx, String animation )

  • float audio_track_get_key_end_offset ( int idx, int key_idx ) const

  • float audio_track_get_key_start_offset ( int idx, int key_idx ) const



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

  • void audio_track_set_key_start_offset ( int idx, int key_idx, float offset )

  • void audio_track_set_key_stream ( int idx, int key_idx, Resource stream )

  • Vector2 bezier_track_get_key_in_handle ( int idx, int key_idx ) const

  • Vector2 bezier_track_get_key_out_handle ( int idx, int key_idx ) const

  • float bezier_track_get_key_value ( int idx, int key_idx ) const



  • void bezier_track_set_key_in_handle ( int idx, int key_idx, Vector2 in_handle )

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

  • void bezier_track_set_key_value ( int idx, int key_idx, float value )

  • void clear ( )

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


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


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.


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


  • String method_track_get_name ( int idx, int key_idx ) const

Returns the method name of a method track.


  • Array method_track_get_params ( int 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 ( int idx )

Remove a track by specifying the track index.


Find 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 ( int idx ) const

Returns true if the track at idx wraps the interpolation loop. Default value: true.


Returns the interpolation type of a given track, from the INTERPOLATION_* enum.


  • int track_get_key_count ( int idx ) const

Returns the amount of keys in a given track.


  • float track_get_key_time ( int idx, int key_idx ) const

Returns the time at which the key is located.


  • float track_get_key_transition ( int idx, int key_idx ) const

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


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


Get the path of a track. for more information on the path format, see track_set_path


Get the type of a track.


Insert a generic key in a given track.


  • bool track_is_enabled ( int idx ) const

Returns true if the track at index idx is enabled.


  • bool track_is_imported ( int idx ) const

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


  • void track_move_down ( int idx )

Move a track down.


  • void track_move_up ( int idx )

Move a track up.


  • void track_remove_key ( int idx, int key_idx )

Remove a key by index in a given track.


  • void track_remove_key_at_position ( int idx, float position )

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


  • void track_set_enabled ( int idx, bool enabled )

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


  • void track_set_imported ( int idx, bool imported )

Set the given track as imported or not.


  • void track_set_interpolation_loop_wrap ( int idx, bool interpolation )

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


Set the interpolation type of a given track, from the INTERPOLATION_* enum.


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

Set the transition curve (easing) for a specific key (see built-in math function “ease”).


Set the value of an existing key.


Set 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 “:”.

Example: “character/skeleton:ankle” or “character/mesh:transform/local”.


  • void track_swap ( int idx, int with_idx )

Insert a transform key for a transform track.


  • Array transform_track_interpolate ( int idx, float 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 (Quat) and scale (Vector3).


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


Returns the update mode of a value track.


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