AnimationMixer
Base class for AnimationPlayer and AnimationTree.
Base class for AnimationPlayer and AnimationTree.
Base class for AnimationPlayer and AnimationTree to manage animation lists. It also has general properties and methods for playback and blending.
After instantiating the playback information data within the extended class, the blending is processed by the AnimationMixer.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties10
ActiveProperty
public bool Active { get; set; }If true, the AnimationMixer will be processing.
AudioMaxPolyphonyProperty
public int AudioMaxPolyphony { get; set; }The number of possible simultaneous sounds for each of the assigned AudioStreamPlayers.
For example, if this value is 32 and the animation has two audio tracks, the two AudioStreamPlayers assigned can play simultaneously up to 32 voices each.
CallbackModeDiscreteProperty
public AnimationMixer.AnimationCallbackModeDiscrete CallbackModeDiscrete { get; set; }Ordinarily, tracks can be set to Animation.UpdateMode.Discrete to update infrequently, usually when using nearest interpolation.
However, when blending with Animation.UpdateMode.Continuous several results are considered. The AnimationMixer.CallbackModeDiscrete specify it explicitly. See also AnimationMixer.AnimationCallbackModeDiscrete.
To make the blended results look good, it is recommended to set this to AnimationMixer.AnimationCallbackModeDiscrete.ForceContinuous 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.
CallbackModeMethodProperty
public AnimationMixer.AnimationCallbackModeMethod CallbackModeMethod { get; set; }Controls Method-track call timing. Deferred queues calls after animation processing; Immediate invokes during processing. Deferred results can appear after Advance(). Do not restructure the playing hierarchy in an Immediate callback.
CallbackModeProcessProperty
public AnimationMixer.AnimationCallbackModeProcess CallbackModeProcess { get; set; }Selects physics-step, frame-based or manual processing. Manual requires the timing owner to call Advance(). A physics callback does not turn direct Position animation into collision-resolved movement.
DeterministicProperty
public bool Deterministic { get; set; }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.
ResetOnSaveProperty
public bool ResetOnSave { get; set; }This is used by the editor. If set to true, the scene will be saved with the effects of the reset animation (the animation with the key "RESET") applied as if it had been seeked to time 0, with the editor keeping the values that the scene had before saving.
This makes it more convenient to preview and edit animations in the editor, as changes to the scene will not be saved as long as they are set in the reset animation.
RootEntityProperty
public EntityPath RootEntity { get; set; }The node which node path references will travel from.
RootMotionLocalProperty
public bool RootMotionLocal { get; set; }If true, AnimationMixer.GetRootMotionPosition value is extracted as a local translation value before blending. In other words, it is treated like the translation is done after the rotation.
RootMotionTrackProperty
public EntityPath RootMotionTrack { get; set; }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 AnimationMixer.RootMotionTrack uses the same format as Animation.TrackSetPath, but note that a bone must be specified.
If the track has type Animation.TrackType.Position3D, Animation.TrackType.Rotation3D, or Animation.TrackType.Scale3D the transformation will be canceled visually, and the animation will appear to stay in place. See also AnimationMixer.GetRootMotionPosition, AnimationMixer.GetRootMotionRotation, AnimationMixer.GetRootMotionScale, and RootMotionView.
Methods42
AddAnimationLibraryError
public Error AddAnimationLibrary(StringName name, AnimationLibrary library);Adds library to the animation player, under the key name.
AnimationMixer has a global library by default with an empty string as key. For adding an animation to the global library:
| Name | Type | Default |
|---|---|---|
name | StringName | — |
library | AnimationLibrary | — |
ErrorAdvancevoid
public void Advance(double delta);Explicitly processes delta seconds of animation. Use CallbackModeProcess=Manual for custom timing, avoiding an extra automatic step. A zero step applies the current pose. In AnimationPlayer an explicit step can advance a paused but still assigned clip.
| Name | Type | Default |
|---|---|---|
delta | double | — |
Capturevoid
public void Capture(StringName name, double duration, Tween.TransitionType transType = Tween.TransitionType.Linear, Tween.EaseType easeType = Tween.EaseType.In);If the animation track specified by name has an option Animation.UpdateMode.Capture, stores current values of the objects indicated by the track path as a cache. If there is already a captured cache, the old cache is discarded.
After this it will interpolate with current animation blending result during the playback process for the time specified by duration, working like a crossfade.
You can specify trans_type as the curve for the interpolation. For better results, it may be appropriate to specify Tween.TransitionType.Linear for cases where the first key of the track begins with a non-zero value or where the key value does not change, and Tween.TransitionType.Quad for cases where the key value changes linearly.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
duration | double | — |
transType | Tween.TransitionType | Tween.TransitionType.Linear |
easeType | Tween.EaseType | Tween.EaseType.In |
ClearCachesvoid
public void ClearCaches();AnimationMixer caches animated nodes. It may not notice if a node disappears; AnimationMixer.ClearCaches forces it to update the cache again.
FindAnimationStringName
public StringName FindAnimation(Animation animation);Returns the key of animation or an empty StringName if not found.
| Name | Type | Default |
|---|---|---|
animation | Animation | — |
StringNameFindAnimationLibraryStringName
public StringName FindAnimationLibrary(Animation animation);Returns the key for the AnimationLibrary that contains animation or an empty StringName if not found.
| Name | Type | Default |
|---|---|---|
animation | Animation | — |
StringNameGetAnimationAnimation
public Animation GetAnimation(StringName name);Returns the Animation with the key name. If the animation does not exist, null is returned and an error is logged.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
AnimationGetAnimationLibraryAnimationLibrary
public AnimationLibrary GetAnimationLibrary(StringName name);Returns the first AnimationLibrary with key name or null if not found.
To get the AnimationMixer's global animation library, use get_animation_library("").
| Name | Type | Default |
|---|---|---|
name | StringName | — |
AnimationLibraryGetAnimationLibraryListReckfell.Collections.Array<StringName>
public Reckfell.Collections.Array<StringName> GetAnimationLibraryList();Returns the list of stored library keys.
Reckfell.Collections.Array<StringName>GetAnimationListstring[]
public string[] GetAnimationList();Returns the list of stored animation keys.
string[]GetAudioMaxPolyphonyint
public int GetAudioMaxPolyphony();intGetCallbackModeDiscreteAnimationMixer.AnimationCallbackModeDiscrete
public AnimationMixer.AnimationCallbackModeDiscrete GetCallbackModeDiscrete();AnimationMixer.AnimationCallbackModeDiscreteGetCallbackModeMethodAnimationMixer.AnimationCallbackModeMethod
public AnimationMixer.AnimationCallbackModeMethod GetCallbackModeMethod();AnimationMixer.AnimationCallbackModeMethodGetCallbackModeProcessAnimationMixer.AnimationCallbackModeProcess
public AnimationMixer.AnimationCallbackModeProcess GetCallbackModeProcess();AnimationMixer.AnimationCallbackModeProcessGetRootEntityEntityPath
public EntityPath GetRootEntity();EntityPathGetRootMotionPositionVector3
public Vector3 GetRootMotionPosition();Returns extracted root-motion displacement for the last processed step, not velocity or the body world position. For CharacterBody3D, transform to the intended coordinate frame, divide displacement by delta for Velocity, then use MoveAndSlide(). Do not apply the same displacement directly a second time.
Vector3GetRootMotionPositionAccumulatorVector3
public Vector3 GetRootMotionPositionAccumulator();Retrieve the blended value of the position tracks with the AnimationMixer.RootMotionTrack 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:
However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.
Vector3GetRootMotionRotationQuaternion
public Quaternion GetRootMotionRotation();Retrieve the motion delta of rotation with the AnimationMixer.RootMotionTrack as a Quaternion that can be used elsewhere.
If AnimationMixer.RootMotionTrack is not a path to a track of type Animation.TrackType.Rotation3D, returns Quaternion(0, 0, 0, 1).
See also AnimationMixer.RootMotionTrack and RootMotionView.
The most basic example is applying rotation to CharacterBody3D:
QuaternionGetRootMotionRotationAccumulatorQuaternion
public Quaternion GetRootMotionRotationAccumulator();Retrieve the blended value of the rotation tracks with the AnimationMixer.RootMotionTrack as a Quaternion that can be used elsewhere.
This is necessary to apply the root motion position correctly, taking rotation into account. See also AnimationMixer.GetRootMotionPosition.
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:
However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.
QuaternionGetRootMotionScaleVector3
public Vector3 GetRootMotionScale();Retrieve the motion delta of scale with the AnimationMixer.RootMotionTrack as a Vector3 that can be used elsewhere.
If AnimationMixer.RootMotionTrack is not a path to a track of type Animation.TrackType.Scale3D, returns Vector3(0, 0, 0).
See also AnimationMixer.RootMotionTrack and RootMotionView.
The most basic example is applying scale to CharacterBody3D:
Vector3GetRootMotionScaleAccumulatorVector3
public Vector3 GetRootMotionScaleAccumulator();Retrieve the blended value of the scale tracks with the AnimationMixer.RootMotionTrack 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:
However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.
Vector3GetRootMotionTrackEntityPath
public EntityPath GetRootMotionTrack();EntityPathHasAnimationbool
public bool HasAnimation(StringName name);Returns true if the AnimationMixer stores an Animation with key name.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
boolHasAnimationLibrarybool
public bool HasAnimationLibrary(StringName name);Returns true if the AnimationMixer stores an AnimationLibrary with key name.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
boolIsActivebool
public bool IsActive();boolIsDeterministicbool
public bool IsDeterministic();boolIsResetOnSaveEnabledbool
public bool IsResetOnSaveEnabled();boolIsRootMotionLocalbool
public bool IsRootMotionLocal();boolRemoveAnimationLibraryvoid
public void RemoveAnimationLibrary(StringName name);Removes the AnimationLibrary associated with the key name.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
RenameAnimationLibraryvoid
public void RenameAnimationLibrary(StringName name, StringName newname);Moves the AnimationLibrary associated with the key name to the key newname.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
newname | StringName | — |
SetActivevoid
public void SetActive(bool active);| Name | Type | Default |
|---|---|---|
active | bool | — |
SetAudioMaxPolyphonyvoid
public void SetAudioMaxPolyphony(int maxPolyphony);| Name | Type | Default |
|---|---|---|
maxPolyphony | int | — |
SetCallbackModeDiscretevoid
public void SetCallbackModeDiscrete(AnimationMixer.AnimationCallbackModeDiscrete mode);| Name | Type | Default |
|---|---|---|
mode | AnimationMixer.AnimationCallbackModeDiscrete | — |
SetCallbackModeMethodvoid
public void SetCallbackModeMethod(AnimationMixer.AnimationCallbackModeMethod mode);| Name | Type | Default |
|---|---|---|
mode | AnimationMixer.AnimationCallbackModeMethod | — |
SetCallbackModeProcessvoid
public void SetCallbackModeProcess(AnimationMixer.AnimationCallbackModeProcess mode);| Name | Type | Default |
|---|---|---|
mode | AnimationMixer.AnimationCallbackModeProcess | — |
SetDeterministicvoid
public void SetDeterministic(bool deterministic);| Name | Type | Default |
|---|---|---|
deterministic | bool | — |
SetResetOnSaveEnabledvoid
public void SetResetOnSaveEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetRootEntityvoid
public void SetRootEntity(EntityPath path);| Name | Type | Default |
|---|---|---|
path | EntityPath | — |
SetRootMotionLocalvoid
public void SetRootMotionLocal(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetRootMotionTrackvoid
public void SetRootMotionTrack(EntityPath path);| Name | Type | Default |
|---|---|---|
path | EntityPath | — |
_PostProcessKeyValue2 overloads
public Variant _PostProcessKeyValue(Animation animation, int track, Variant value, ReckfellObject @object, int objectIdx);A virtual function for processing after getting a key during playback.
| Name | Type | Default |
|---|---|---|
animation | Animation | — |
track | int | — |
value | Variant | — |
object | ReckfellObject | — |
objectIdx | int | — |
Variantpublic virtual Variant _PostProcessKeyValue(Animation animation, int track, Variant value, ulong objectId, int objectSubIdx);A virtual function for processing after getting a key during playback.
| Name | Type | Default |
|---|---|---|
animation | Animation | — |
track | int | — |
value | Variant | — |
objectId | ulong | — |
objectSubIdx | int | — |
VariantSignals and events7
AnimationFinishedEvent
public event AnimationMixer.AnimationFinishedEventHandler AnimationFinished;Reports the normal completion of an individual nonlooping clip. Stop() and seeking to the end do not substitute for it. In AnimationTree, clip completion does not mean that the whole graph or gameplay action has finished. Account for cancellation and object deletion when awaiting it.
| Name | Type | Default |
|---|---|---|
animName | StringName | — |
AnimationLibrariesUpdatedEvent
public event Action AnimationLibrariesUpdated;Notifies when the animation libraries have changed.
AnimationListChangedEvent
public event Action AnimationListChanged;Notifies when an animation list is changed.
AnimationStartedEvent
public event AnimationMixer.AnimationStartedEventHandler AnimationStarted;Notifies when an animation starts playing. Note: This signal is not emitted if an animation is looping.
| Name | Type | Default |
|---|---|---|
animName | StringName | — |
CachesClearedEvent
public event Action CachesCleared;Notifies when the caches have been cleared, either automatically, or manually via AnimationMixer.ClearCaches.
MixerAppliedEvent
public event Action MixerApplied;Notifies when the blending result related have been applied to the target objects.
MixerUpdatedEvent
public event Action MixerUpdated;Notifies when the property related process have been updated.
AnimationMixer.AnimationCallbackModeDiscrete
AnimationMixer.AnimationCallbackModeMethod
| Value | Description |
|---|---|
Deferred = 0 | Batch method calls during the animation process, then do the calls after events are processed. This avoids bugs involving deleting nodes or modifying the AnimationPlayer while playing. |
Immediate = 1 | Make method calls immediately when reached in the animation. |
AnimationMixer.AnimationCallbackModeProcess
| Value | Description |
|---|---|
Idle = 1 | Process animation during process frames (see |
Manual = 2 | Do not process animation. Use |
Physics = 0 | Process animation during physics frames (see |