AnimationMixer

Hereda: Node < Object

Heredado por: AnimationPlayer, AnimationTree

Clase base para AnimationPlayer y AnimationTree.

Descripción

Clase base para AnimationPlayer y AnimationTree para gestionar listas de animación. También tiene propiedades y métodos generales para la reproducción y la mezcla.

Después de instanciar los datos de información de reproducción dentro de la clase extendida, la mezcla es procesada por el AnimationMixer.

Tutoriales

Propiedades

bool

active

true

int

audio_max_polyphony

32

AnimationCallbackModeDiscrete

callback_mode_discrete

1

AnimationCallbackModeMethod

callback_mode_method

0

AnimationCallbackModeProcess

callback_mode_process

1

bool

deterministic

false

bool

reset_on_save

true

bool

root_motion_local

false

NodePath

root_motion_track

NodePath("")

NodePath

root_node

NodePath("..")

Métodos

Variant

_post_process_key_value(animation: Animation, track: int, value: Variant, object_id: int, object_sub_idx: int) virtual const

Error

add_animation_library(name: StringName, library: AnimationLibrary)

void

advance(delta: float)

void

capture(name: StringName, duration: float, trans_type: TransitionType = 0, ease_type: EaseType = 0)

void

clear_caches()

StringName

find_animation(animation: Animation) const

StringName

find_animation_library(animation: Animation) const

Animation

get_animation(name: StringName) const

AnimationLibrary

get_animation_library(name: StringName) const

Array[StringName]

get_animation_library_list() const

PackedStringArray

get_animation_list() const

Vector3

get_root_motion_position() const

Vector3

get_root_motion_position_accumulator() const

Quaternion

get_root_motion_rotation() const

Quaternion

get_root_motion_rotation_accumulator() const

Vector3

get_root_motion_scale() const

Vector3

get_root_motion_scale_accumulator() const

bool

has_animation(name: StringName) const

bool

has_animation_library(name: StringName) const

void

remove_animation_library(name: StringName)

void

rename_animation_library(name: StringName, newname: StringName)


Señales

animation_finished(anim_name: StringName) 🔗

Notifica cuando una animación ha terminado de reproducirse.

Nota: Esta señal no se emite si una animación está en bucle.


animation_libraries_updated() 🔗

Notifica cuando las bibliotecas de animación han cambiado.


animation_list_changed() 🔗

Notifica cuando una lista de animación cambia.


animation_started(anim_name: StringName) 🔗

Notifica cuando una animación comienza a reproducirse.

Nota: Esta señal no se emite si una animación está en bucle.


caches_cleared() 🔗

Notifica cuando las cachés se han limpiado, ya sea automáticamente o manualmente a través del clear_caches().


mixer_applied() 🔗

Notifica cuando el resultado de la mezcla se ha aplicado a los objetos de destino.


mixer_updated() 🔗

Notifica cuando se han actualizado los procesos relacionados con la propiedad.


Enumeraciones

enum AnimationCallbackModeProcess: 🔗

AnimationCallbackModeProcess ANIMATION_CALLBACK_MODE_PROCESS_PHYSICS = 0

Procesa la animación durante los frames de física (véase Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS). Esto es especialmente útil cuando se animan cuerpos físicos.

AnimationCallbackModeProcess ANIMATION_CALLBACK_MODE_PROCESS_IDLE = 1

Procesa la animación durante los frames de proceso (véase Node.NOTIFICATION_INTERNAL_PROCESS).

AnimationCallbackModeProcess ANIMATION_CALLBACK_MODE_PROCESS_MANUAL = 2

No procesar la animación. Utiliza advance() para procesar la animación manualmente.


enum AnimationCallbackModeMethod: 🔗

AnimationCallbackModeMethod ANIMATION_CALLBACK_MODE_METHOD_DEFERRED = 0

Metodos de procesos por lotes llamados durante el proceso de animación, y despues que los eventos son procesados hacer los llamados. Esto evita los errores que implican borrar nodos o modificar el AnimationPlayer mientras se está reproduciendo.

AnimationCallbackModeMethod ANIMATION_CALLBACK_MODE_METHOD_IMMEDIATE = 1

Hace llamadas a método inmediatamente cuando se alcanza en la animación.


enum AnimationCallbackModeDiscrete: 🔗

AnimationCallbackModeDiscrete ANIMATION_CALLBACK_MODE_DISCRETE_DOMINANT = 0

Un valor de pista Animation.UPDATE_DISCRETE tiene prioridad al mezclar valores de pista Animation.UPDATE_CONTINUOUS o Animation.UPDATE_CAPTURE y valores de pista Animation.UPDATE_DISCRETE.

AnimationCallbackModeDiscrete ANIMATION_CALLBACK_MODE_DISCRETE_RECESSIVE = 1

Un valor de pista Animation.UPDATE_CONTINUOUS o Animation.UPDATE_CAPTURE tiene prioridad al mezclar los valores de pista Animation.UPDATE_CONTINUOUS o Animation.UPDATE_CAPTURE y los valores de pista Animation.UPDATE_DISCRETE. Este es el comportamiento predeterminado para AnimationPlayer.

AnimationCallbackModeDiscrete ANIMATION_CALLBACK_MODE_DISCRETE_FORCE_CONTINUOUS = 2

Always treat the Animation.UPDATE_DISCRETE track value as Animation.UPDATE_CONTINUOUS with Animation.INTERPOLATION_NEAREST. This is the default behavior for AnimationTree.

If a value track has un-interpolatable type key values, it is internally converted to use ANIMATION_CALLBACK_MODE_DISCRETE_RECESSIVE with Animation.UPDATE_DISCRETE.

Un-interpolatable type list:

@GlobalScope.TYPE_BOOL and @GlobalScope.TYPE_INT are treated as @GlobalScope.TYPE_FLOAT during blending and rounded when the result is retrieved.

It is same for arrays and vectors with them such as @GlobalScope.TYPE_PACKED_INT32_ARRAY or @GlobalScope.TYPE_VECTOR2I, they are treated as @GlobalScope.TYPE_PACKED_FLOAT32_ARRAY or @GlobalScope.TYPE_VECTOR2. Also note that for arrays, the size is also interpolated.

@GlobalScope.TYPE_STRING and @GlobalScope.TYPE_STRING_NAME are interpolated between character codes and lengths, but note that there is a difference in algorithm between interpolation between keys and interpolation by blending.


Descripciones de Propiedades

bool active = true 🔗

  • void set_active(value: bool)

  • bool is_active()

Si es true, el AnimationMixer estará procesando.


int audio_max_polyphony = 32 🔗

  • void set_audio_max_polyphony(value: int)

  • int get_audio_max_polyphony()

El número de sonidos simultáneos posibles para cada uno de los AudioStreamPlayers asignados.

Por ejemplo, si este valor es 32 y la animación tiene dos pistas de audio, los dos AudioStreamPlayer asignados pueden reproducir simultáneamente hasta 32 voces cada uno.


AnimationCallbackModeDiscrete callback_mode_discrete = 1 🔗

Ordinarily, tracks can be set to Animation.UPDATE_DISCRETE to update infrequently, usually when using nearest interpolation.

However, when blending with Animation.UPDATE_CONTINUOUS several results are considered. The callback_mode_discrete specify it explicitly. See also AnimationCallbackModeDiscrete.

To make the blended results look good, it is recommended to set this to ANIMATION_CALLBACK_MODE_DISCRETE_FORCE_CONTINUOUS to update every frame during blending. Other values exist for compatibility and they are fine if there is no blending, but not so, may produce artifacts.


AnimationCallbackModeMethod callback_mode_method = 0 🔗

The call mode used for "Call Method" tracks.


AnimationCallbackModeProcess callback_mode_process = 1 🔗

La notificación de proceso en la que se actualizan las animaciones.


bool deterministic = false 🔗

  • void set_deterministic(value: bool)

  • bool is_deterministic()

If true, the blending uses the deterministic algorithm. The total weight is not normalized and the result is accumulated with an initial value (0 or a "RESET" animation if present).

This means that if the total amount of blending is 0.0, the result is equal to the "RESET" animation.

If the number of tracks between the blended animations is different, the animation with the missing track is treated as if it had the initial value.

If false, The blend does not use the deterministic algorithm. The total weight is normalized and always 1.0. If the number of tracks between the blended animations is different, nothing is done about the animation that is missing a track.

Note: In AnimationTree, the blending with AnimationNodeAdd2, AnimationNodeAdd3, AnimationNodeSub2 or the weight greater than 1.0 may produce unexpected results.

For example, if AnimationNodeAdd2 blends two nodes with the amount 1.0, then total weight is 2.0 but it will be normalized to make the total amount 1.0 and the result will be equal to AnimationNodeBlend2 with the amount 0.5.


bool reset_on_save = true 🔗

  • void set_reset_on_save_enabled(value: bool)

  • bool is_reset_on_save_enabled()

Esto lo utiliza el editor. Si se establece en true, la escena se guardará con los efectos de la animación de reinicio (la animación con la clave "RESET") aplicada como si se hubiera buscado hasta el tiempo 0, y el editor conservará los valores que la escena tenía antes de guardar.

Esto hace que sea más conveniente previsualizar y editar animaciones en el editor, ya que los cambios en la escena no se guardarán mientras estén establecidos en la animación de reinicio.


bool root_motion_local = false 🔗

  • void set_root_motion_local(value: bool)

  • bool is_root_motion_local()

Si es true, el valor de get_root_motion_position() se extrae como un valor de traslación local antes de la mezcla. En otras palabras, se trata como si la traslación se hiciera después de la rotación.


NodePath root_motion_track = NodePath("") 🔗

The path to the Animation track used for root motion. 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. The root_motion_track uses the same format as Animation.track_set_path(), but note that a bone must be specified.

If the track has type Animation.TYPE_POSITION_3D, Animation.TYPE_ROTATION_3D, or Animation.TYPE_SCALE_3D the transformation will be canceled visually, and the animation will appear to stay in place. See also get_root_motion_position(), get_root_motion_rotation(), get_root_motion_scale(), and RootMotionView.


NodePath root_node = NodePath("..") 🔗

El nodo desde el cual viajarán las referencias de la ruta del nodo.


Descripciones de Métodos

Variant _post_process_key_value(animation: Animation, track: int, value: Variant, object_id: int, object_sub_idx: int) virtual const 🔗

Una función virtual para procesar después de obtener una clave durante la reproducción.


Error add_animation_library(name: StringName, library: AnimationLibrary) 🔗

Añade library al reproductor de animación, bajo la clave name.

AnimationMixer tiene una biblioteca global por defecto con una string vacía como clave. Para añadir una animación a la biblioteca global:

var global_library = mixer.get_animation_library("")
global_library.add_animation("animation_name", animation_resource)

void advance(delta: float) 🔗

Avanza manualmente las animaciones en el tiempo especificado (en segundos).


void capture(name: StringName, duration: float, trans_type: TransitionType = 0, ease_type: EaseType = 0) 🔗

Si la pista de animación especificada por name tiene una opción Animation.UPDATE_CAPTURE, almacena los valores actuales de los objetos indicados por la ruta de la pista como una caché. Si ya existe una caché capturada, la caché anterior se descarta.

Después de esto, se interpolará con el resultado actual de la mezcla de animación durante el proceso de reproducción durante el tiempo especificado por duration, funcionando como un fundido cruzado.

Puedes especificar trans_type como la curva para la interpolación. Para obtener mejores resultados, puede ser apropiado especificar Tween.TRANS_LINEAR para los casos en que la primera clave de la pista comience con un valor distinto de cero o donde el valor de la clave no cambie, y Tween.TRANS_QUAD para los casos en que el valor de la clave cambie linealmente.


void clear_caches() 🔗

AnimationMixer guarda en caché los nodos animados. Es posible que no note si un nodo desaparece; clear_caches() fuerza a actualizar la caché de nuevo.


StringName find_animation(animation: Animation) const 🔗

Devuelve la clave de animation o un StringName vacío si no se encuentra.


StringName find_animation_library(animation: Animation) const 🔗

Devuelve la clave de la AnimationLibrary que contiene animation o un StringName vacío si no se encuentra.


Animation get_animation(name: StringName) const 🔗

Devuelve la Animation con la clave name. Si la animación no existe, se devuelve null y se registra un error.


AnimationLibrary get_animation_library(name: StringName) const 🔗

Devuelve la primera AnimationLibrary con la clave name o null si no se encuentra.

Para obtener la biblioteca de animación global de AnimationMixer, utiliza get_animation_library("").


Array[StringName] get_animation_library_list() const 🔗

Devuelve la lista de claves de biblioteca almacenadas.


PackedStringArray get_animation_list() const 🔗

Devuelve la lista de claves de animación almacenadas.


Vector3 get_root_motion_position() const 🔗

Retrieve the motion delta of position with the root_motion_track as a Vector3 that can be used elsewhere.

If root_motion_track is not a path to a track of type Animation.TYPE_POSITION_3D, returns Vector3(0, 0, 0).

See also root_motion_track and RootMotionView.

The most basic example is applying position to CharacterBody3D:

var current_rotation

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        current_rotation = get_quaternion()
        state_machine.travel("Animate")
    var velocity = current_rotation * animation_tree.get_root_motion_position() / delta
    set_velocity(velocity)
    move_and_slide()

By using this in combination with get_root_motion_rotation_accumulator(), you can apply the root motion position more correctly to account for the rotation of the node.

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        state_machine.travel("Animate")
    set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
    var velocity = (animation_tree.get_root_motion_rotation_accumulator().inverse() * get_quaternion()) * animation_tree.get_root_motion_position() / delta
    set_velocity(velocity)
    move_and_slide()

If root_motion_local is true, returns the pre-multiplied translation value with the inverted rotation.

In this case, the code can be written as follows:

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        state_machine.travel("Animate")
    set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
    var velocity = get_quaternion() * animation_tree.get_root_motion_position() / delta
    set_velocity(velocity)
    move_and_slide()

Vector3 get_root_motion_position_accumulator() const 🔗

Retrieve the blended value of the position tracks with the root_motion_track as a Vector3 that can be used elsewhere.

This is useful in cases where you want to respect the initial key values of the animation.

For example, if an animation with only one key Vector3(0, 0, 0) is played in the previous frame and then an animation with only one key Vector3(1, 0, 1) is played in the next frame, the difference can be calculated as follows:

var prev_root_motion_position_accumulator

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        state_machine.travel("Animate")
    var current_root_motion_position_accumulator = animation_tree.get_root_motion_position_accumulator()
    var difference = current_root_motion_position_accumulator - prev_root_motion_position_accumulator
    prev_root_motion_position_accumulator = current_root_motion_position_accumulator
    transform.origin += difference

However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.


Quaternion get_root_motion_rotation() const 🔗

Recupera el delta de movimiento de rotación con root_motion_track como un Quaternion que puede ser usado en otro lugar.

Si root_motion_track no es una ruta a una pista de tipo Animation.TYPE_ROTATION_3D, devuelve Quaternion(0, 0, 0, 1).

Véase también root_motion_track y RootMotionView.

El ejemplo más básico es aplicar la rotación a CharacterBody3D:

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        state_machine.travel("Animate")
    set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())

Quaternion get_root_motion_rotation_accumulator() const 🔗

Retrieve the blended value of the rotation tracks with the root_motion_track as a Quaternion that can be used elsewhere.

This is necessary to apply the root motion position correctly, taking rotation into account. See also get_root_motion_position().

Also, this is useful in cases where you want to respect the initial key values of the animation.

For example, if an animation with only one key Quaternion(0, 0, 0, 1) is played in the previous frame and then an animation with only one key Quaternion(0, 0.707, 0, 0.707) is played in the next frame, the difference can be calculated as follows:

var prev_root_motion_rotation_accumulator

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        state_machine.travel("Animate")
    var current_root_motion_rotation_accumulator = animation_tree.get_root_motion_rotation_accumulator()
    var difference = prev_root_motion_rotation_accumulator.inverse() * current_root_motion_rotation_accumulator
    prev_root_motion_rotation_accumulator = current_root_motion_rotation_accumulator
    transform.basis *=  Basis(difference)

However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.


Vector3 get_root_motion_scale() const 🔗

Recupera el delta de movimiento de la escala con root_motion_track como un Vector3 que puede ser usado en otro lugar.

Si root_motion_track no es una ruta a una pista de tipo Animation.TYPE_SCALE_3D, devuelve Vector3(0, 0, 0).

Véase también root_motion_track y RootMotionView.

El ejemplo más básico es aplicar la escala a CharacterBody3D:

var current_scale = Vector3(1, 1, 1)
var scale_accum = Vector3(1, 1, 1)

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        current_scale = get_scale()
        scale_accum = Vector3(1, 1, 1)
        state_machine.travel("Animate")
    scale_accum += animation_tree.get_root_motion_scale()
    set_scale(current_scale * scale_accum)

Vector3 get_root_motion_scale_accumulator() const 🔗

Retrieve the blended value of the scale tracks with the root_motion_track as a Vector3 that can be used elsewhere.

For example, if an animation with only one key Vector3(1, 1, 1) is played in the previous frame and then an animation with only one key Vector3(2, 2, 2) is played in the next frame, the difference can be calculated as follows:

var prev_root_motion_scale_accumulator

func _process(delta):
    if Input.is_action_just_pressed("animate"):
        state_machine.travel("Animate")
    var current_root_motion_scale_accumulator = animation_tree.get_root_motion_scale_accumulator()
    var difference = current_root_motion_scale_accumulator - prev_root_motion_scale_accumulator
    prev_root_motion_scale_accumulator = current_root_motion_scale_accumulator
    transform.basis = transform.basis.scaled(difference)

However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.


bool has_animation(name: StringName) const 🔗

Devuelve true si el AnimationMixer almacena una Animation con la clave name.


bool has_animation_library(name: StringName) const 🔗

Devuelve true si el AnimationMixer almacena una AnimationLibrary con la clave name.


void remove_animation_library(name: StringName) 🔗

Elimina la AnimationLibrary asociada con la clave name.


void rename_animation_library(name: StringName, newname: StringName) 🔗

Mueve la AnimationLibrary asociada con la clave name a la clave newname.