AnimationMixer

package
v0.0.0-...-ff35923 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Base class for graphics.gd/classdb/AnimationPlayer and graphics.gd/classdb/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 graphics.gd/classdb/AnimationMixer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type AnimationCallbackModeDiscrete

type AnimationCallbackModeDiscrete int //gd:AnimationMixer.AnimationCallbackModeDiscrete
const (
	// An [Animation.UpdateDiscrete] track value takes precedence when blending [Animation.UpdateContinuous] or [Animation.UpdateCapture] track values and [Animation.UpdateDiscrete] track values.
	AnimationCallbackModeDiscreteDominant AnimationCallbackModeDiscrete = 0
	// An [Animation.UpdateContinuous] or [Animation.UpdateCapture] track value takes precedence when blending the [Animation.UpdateContinuous] or [Animation.UpdateCapture] track values and the [Animation.UpdateDiscrete] track values. This is the default behavior for [graphics.gd/classdb/AnimationPlayer].
	AnimationCallbackModeDiscreteRecessive AnimationCallbackModeDiscrete = 1
	// Always treat the [Animation.UpdateDiscrete] track value as [Animation.UpdateContinuous] with [Animation.InterpolationNearest]. This is the default behavior for [graphics.gd/classdb/AnimationTree].
	//
	// If a value track has un-interpolatable type key values, it is internally converted to use [AnimationCallbackModeDiscreteRecessive] with [Animation.UpdateDiscrete].
	//
	// Un-interpolatable type list:
	//
	// - [@Globalscope.TypeNil]
	//
	// - [@Globalscope.TypeNodePath]
	//
	// - [@Globalscope.TypeRid]
	//
	// - [@Globalscope.TypeObject]
	//
	// - [@Globalscope.TypeCallable]
	//
	// - [@Globalscope.TypeSignal]
	//
	// - [@Globalscope.TypeDictionary]
	//
	// - [@Globalscope.TypePackedByteArray]
	//
	// [@Globalscope.TypeBool] and [@Globalscope.TypeInt] are treated as [@Globalscope.TypeFloat] during blending and rounded when the result is retrieved.
	//
	// It is same for arrays and vectors with them such as [@Globalscope.TypePackedInt32Array] or [@Globalscope.TypeVector2i], they are treated as [@Globalscope.TypePackedFloat32Array] or [@Globalscope.TypeVector2]. Also note that for arrays, the size is also interpolated.
	//
	// [@Globalscope.TypeString] and [@Globalscope.TypeStringName] are interpolated between character codes and lengths, but note that there is a difference in algorithm between interpolation between keys and interpolation by blending.
	AnimationCallbackModeDiscreteForceContinuous AnimationCallbackModeDiscrete = 2
)

type AnimationCallbackModeMethod

type AnimationCallbackModeMethod int //gd:AnimationMixer.AnimationCallbackModeMethod
const (
	// 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.
	AnimationCallbackModeMethodDeferred AnimationCallbackModeMethod = 0
	// Make method calls immediately when reached in the animation.
	AnimationCallbackModeMethodImmediate AnimationCallbackModeMethod = 1
)

type AnimationCallbackModeProcess

type AnimationCallbackModeProcess int //gd:AnimationMixer.AnimationCallbackModeProcess
const (
	// Process animation during physics frames (see [Node.NotificationInternalPhysicsProcess]). This is especially useful when animating physics bodies.
	AnimationCallbackModeProcessPhysics AnimationCallbackModeProcess = 0
	// Process animation during process frames (see [Node.NotificationInternalProcess]).
	AnimationCallbackModeProcessIdle AnimationCallbackModeProcess = 1
	// Do not process animation. Use [Instance.Advance] to process the animation manually.
	AnimationCallbackModeProcessManual AnimationCallbackModeProcess = 2
)

type Any

type Any interface {
	gd.IsClass
	AsAnimationMixer() Instance
}

type Expanded

type Expanded [1]gdclass.AnimationMixer

func (Expanded) Capture

func (self Expanded) Capture(name string, duration Float.X, trans_type Tween.TransitionType, ease_type Tween.EaseType)

If the animation track specified by 'name' has an option [Animation.UpdateCapture], 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.TransLinear] 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.TransQuad] for cases where the key value changes linearly.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.

func (*Extension[T]) AsAnimationMixer

func (self *Extension[T]) AsAnimationMixer() Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Implementation

type Implementation = implementation

Implementation implements Interface with empty methods.

type Instance

type Instance [1]gdclass.AnimationMixer

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) Active

func (self Instance) Active() bool

func (Instance) AddAnimationLibrary

func (self Instance) AddAnimationLibrary(name string, library AnimationLibrary.Instance) error

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:

var global_library = mixer.GetAnimationLibrary("")
global_library.AddAnimation("animation_name", animation_resource)

func (Instance) Advance

func (self Instance) Advance(delta Float.X)

Manually advance the animations by the specified time (in seconds).

func (Instance) AsAnimationMixer

func (self Instance) AsAnimationMixer() Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AudioMaxPolyphony

func (self Instance) AudioMaxPolyphony() int

func (Instance) CallbackModeDiscrete

func (self Instance) CallbackModeDiscrete() AnimationCallbackModeDiscrete

func (Instance) CallbackModeMethod

func (self Instance) CallbackModeMethod() AnimationCallbackModeMethod

func (Instance) CallbackModeProcess

func (self Instance) CallbackModeProcess() AnimationCallbackModeProcess

func (Instance) Capture

func (self Instance) Capture(name string, duration Float.X)

If the animation track specified by 'name' has an option [Animation.UpdateCapture], 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.TransLinear] 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.TransQuad] for cases where the key value changes linearly.

func (Instance) ClearCaches

func (self Instance) ClearCaches()

graphics.gd/classdb/AnimationMixer caches animated nodes. It may not notice if a node disappears; Instance.ClearCaches forces it to update the cache again.

func (Instance) Deterministic

func (self Instance) Deterministic() bool

func (Instance) FindAnimation

func (self Instance) FindAnimation(animation Animation.Instance) string

Returns the key of 'animation' or an empty string if not found.

func (Instance) FindAnimationLibrary

func (self Instance) FindAnimationLibrary(animation Animation.Instance) string

Returns the key for the graphics.gd/classdb/AnimationLibrary that contains 'animation' or an empty string if not found.

func (Instance) GetAnimation

func (self Instance) GetAnimation(name string) Animation.Instance

Returns the graphics.gd/classdb/Animation with the key 'name'. If the animation does not exist, null is returned and an error is logged.

func (Instance) GetAnimationLibrary

func (self Instance) GetAnimationLibrary(name string) AnimationLibrary.Instance

Returns the first graphics.gd/classdb/AnimationLibrary with key 'name' or null if not found.

To get the graphics.gd/classdb/AnimationMixer's global animation library, use get_animation_library("").

func (Instance) GetAnimationLibraryList

func (self Instance) GetAnimationLibraryList() []string

Returns the list of stored library keys.

func (Instance) GetAnimationList

func (self Instance) GetAnimationList() []string

Returns the list of stored animation keys.

func (Instance) GetRootMotionPosition

func (self Instance) GetRootMotionPosition() Vector3.XYZ

Retrieve the motion delta of position with the Instance.RootMotionTrack as a [Vector3.XYZ] that can be used elsewhere.

If Instance.RootMotionTrack is not a path to a track of type [Animation.TypePosition3d], returns Vector3(0, 0, 0).

See also Instance.RootMotionTrack and graphics.gd/classdb/RootMotionView.

The most basic example is applying position to graphics.gd/classdb/CharacterBody3D:

if Input.IsActionJustPressed("animate", false) {
	current_rotation = characterBody3D.AsNode3D().Quaternion()
	animationNodeStateMachinePlayback.Travel("Animate")
}
var velocity = Vector3.DivX(Quaternion.Rotate(animationTree.AsAnimationMixer().GetRootMotionPosition(), current_rotation), delta)
characterBody3D.SetVelocity(velocity)
characterBody3D.MoveAndSlide()

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

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

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

func (Instance) GetRootMotionPositionAccumulator

func (self Instance) GetRootMotionPositionAccumulator() Vector3.XYZ

Retrieve the blended value of the position tracks with the Instance.RootMotionTrack as a [Vector3.XYZ] 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 Vector3.XYZ
if Input.IsActionJustPressed("animate", false) {
	animationNodeStateMachinePlayback.Travel("Animate")
}
var current_root_motion_position_accumulator = animationTree.AsAnimationMixer().GetRootMotionPositionAccumulator()
var difference = Vector3.Sub(current_root_motion_position_accumulator, prev_root_motion_position_accumulator)
prev_root_motion_position_accumulator = current_root_motion_position_accumulator
transform := characterBody3D.AsNode3D().Transform()
transform.Origin = Vector3.Add(transform.Origin, difference)
characterBody3D.AsNode3D().SetTransform(transform)

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

func (Instance) GetRootMotionRotation

func (self Instance) GetRootMotionRotation() Quaternion.IJKX

Retrieve the motion delta of rotation with the Instance.RootMotionTrack as a [Quaternion.IJKX] that can be used elsewhere.

If Instance.RootMotionTrack is not a path to a track of type [Animation.TypeRotation3d], returns Quaternion(0, 0, 0, 1).

See also Instance.RootMotionTrack and graphics.gd/classdb/RootMotionView.

The most basic example is applying rotation to graphics.gd/classdb/CharacterBody3D:

if Input.IsActionJustPressed("animate", false) {
	animationNodeStateMachinePlayback.Travel("Animate")
}
characterBody3D.AsNode3D().SetQuaternion(Quaternion.Mul(characterBody3D.AsNode3D().Quaternion(), animationTree.AsAnimationMixer().GetRootMotionRotation()))

func (Instance) GetRootMotionRotationAccumulator

func (self Instance) GetRootMotionRotationAccumulator() Quaternion.IJKX

Retrieve the blended value of the rotation tracks with the Instance.RootMotionTrack as a [Quaternion.IJKX] that can be used elsewhere.

This is necessary to apply the root motion position correctly, taking rotation into account. See also Instance.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:

var prev_root_motion_rotation_accumulator Quaternion.IJKX

if Input.IsActionJustPressed("animate", false) {
	animationNodeStateMachinePlayback.Travel("Animate")
}
var current_root_motion_rotation_accumulator = animationTree.AsAnimationMixer().GetRootMotionRotationAccumulator()
var difference = Quaternion.Mul(Quaternion.Inverse(prev_root_motion_rotation_accumulator), current_root_motion_rotation_accumulator)
prev_root_motion_rotation_accumulator = current_root_motion_rotation_accumulator
transform := characterBody3D.AsNode3D().Transform()
transform.Basis = Basis.Mul(transform.Basis, Quaternion.AsBasis(difference))
characterBody3D.AsNode3D().SetTransform(transform)

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

func (Instance) GetRootMotionScale

func (self Instance) GetRootMotionScale() Vector3.XYZ

Retrieve the motion delta of scale with the Instance.RootMotionTrack as a [Vector3.XYZ] that can be used elsewhere.

If Instance.RootMotionTrack is not a path to a track of type [Animation.TypeScale3d], returns Vector3(0, 0, 0).

See also Instance.RootMotionTrack and graphics.gd/classdb/RootMotionView.

The most basic example is applying scale to graphics.gd/classdb/CharacterBody3D:

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

if Input.IsActionJustPressed("animate", false) {
	current_scale = characterBody3D.AsNode3D().Scale()
	scale_accum = Vector3.New(1, 1, 1)
	animationNodeStateMachinePlayback.Travel("Animate")
}
scale_accum = Vector3.Add(scale_accum, animationTree.AsAnimationMixer().GetRootMotionScale())
characterBody3D.AsNode3D().SetScale(Vector3.Mul(current_scale, scale_accum))

func (Instance) GetRootMotionScaleAccumulator

func (self Instance) GetRootMotionScaleAccumulator() Vector3.XYZ

Retrieve the blended value of the scale tracks with the Instance.RootMotionTrack as a [Vector3.XYZ] 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 Vector3.XYZ

if Input.IsActionJustPressed("animate", false) {
	animationNodeStateMachinePlayback.Travel("Animate")
}
var current_root_motion_scale_accumulator = animationTree.AsAnimationMixer().GetRootMotionScaleAccumulator()
var difference = Vector3.Sub(current_root_motion_scale_accumulator, prev_root_motion_scale_accumulator)
prev_root_motion_scale_accumulator = current_root_motion_scale_accumulator
transform := characterBody3D.AsNode3D().Transform()
transform.Basis = Basis.Scaled(transform.Basis, difference)
characterBody3D.AsNode3D().SetTransform(transform)

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

func (Instance) HasAnimation

func (self Instance) HasAnimation(name string) bool

Returns true if the graphics.gd/classdb/AnimationMixer stores an graphics.gd/classdb/Animation with key 'name'.

func (Instance) HasAnimationLibrary

func (self Instance) HasAnimationLibrary(name string) bool

Returns true if the graphics.gd/classdb/AnimationMixer stores an graphics.gd/classdb/AnimationLibrary with key 'name'.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) OnAnimationFinished

func (self Instance) OnAnimationFinished(cb func(anim_name string), flags ...Signal.Flags)

func (Instance) OnAnimationLibrariesUpdated

func (self Instance) OnAnimationLibrariesUpdated(cb func(), flags ...Signal.Flags)

func (Instance) OnAnimationListChanged

func (self Instance) OnAnimationListChanged(cb func(), flags ...Signal.Flags)

func (Instance) OnAnimationStarted

func (self Instance) OnAnimationStarted(cb func(anim_name string), flags ...Signal.Flags)

func (Instance) OnCachesCleared

func (self Instance) OnCachesCleared(cb func(), flags ...Signal.Flags)

func (Instance) OnMixerApplied

func (self Instance) OnMixerApplied(cb func(), flags ...Signal.Flags)

func (Instance) OnMixerUpdated

func (self Instance) OnMixerUpdated(cb func(), flags ...Signal.Flags)

func (Instance) RemoveAnimationLibrary

func (self Instance) RemoveAnimationLibrary(name string)

Removes the graphics.gd/classdb/AnimationLibrary associated with the key 'name'.

func (Instance) RenameAnimationLibrary

func (self Instance) RenameAnimationLibrary(name string, newname string)

Moves the graphics.gd/classdb/AnimationLibrary associated with the key 'name' to the key 'newname'.

func (Instance) ResetOnSave

func (self Instance) ResetOnSave() bool

func (Instance) RootMotionLocal

func (self Instance) RootMotionLocal() bool

func (Instance) RootMotionTrack

func (self Instance) RootMotionTrack() string

func (Instance) RootNode

func (self Instance) RootNode() string

func (Instance) SetActive

func (self Instance) SetActive(value bool)

func (Instance) SetAudioMaxPolyphony

func (self Instance) SetAudioMaxPolyphony(value int)

func (Instance) SetCallbackModeDiscrete

func (self Instance) SetCallbackModeDiscrete(value AnimationCallbackModeDiscrete)

func (Instance) SetCallbackModeMethod

func (self Instance) SetCallbackModeMethod(value AnimationCallbackModeMethod)

func (Instance) SetCallbackModeProcess

func (self Instance) SetCallbackModeProcess(value AnimationCallbackModeProcess)

func (Instance) SetDeterministic

func (self Instance) SetDeterministic(value bool)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetResetOnSave

func (self Instance) SetResetOnSave(value bool)

func (Instance) SetRootMotionLocal

func (self Instance) SetRootMotionLocal(value bool)

func (Instance) SetRootMotionTrack

func (self Instance) SetRootMotionTrack(value string)

func (Instance) SetRootNode

func (self Instance) SetRootNode(value string)

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Interface

type Interface interface {
	// A virtual function for processing after getting a key during playback.
	PostProcessKeyValue(animation Animation.Instance, track int, value any, object_id int, object_sub_idx int) any
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL