Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/doc/classes/AnimationMixer.xml
10277 views
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<class name="AnimationMixer" inherits="Node" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3
<brief_description>
4
Base class for [AnimationPlayer] and [AnimationTree].
5
</brief_description>
6
<description>
7
Base class for [AnimationPlayer] and [AnimationTree] to manage animation lists. It also has general properties and methods for playback and blending.
8
After instantiating the playback information data within the extended class, the blending is processed by the [AnimationMixer].
9
</description>
10
<tutorials>
11
<link title="Migrating Animations from Godot 4.0 to 4.3">https://godotengine.org/article/migrating-animations-from-godot-4-0-to-4-3/</link>
12
</tutorials>
13
<methods>
14
<method name="_post_process_key_value" qualifiers="virtual const">
15
<return type="Variant" />
16
<param index="0" name="animation" type="Animation" />
17
<param index="1" name="track" type="int" />
18
<param index="2" name="value" type="Variant" />
19
<param index="3" name="object_id" type="int" />
20
<param index="4" name="object_sub_idx" type="int" />
21
<description>
22
A virtual function for processing after getting a key during playback.
23
</description>
24
</method>
25
<method name="add_animation_library">
26
<return type="int" enum="Error" />
27
<param index="0" name="name" type="StringName" />
28
<param index="1" name="library" type="AnimationLibrary" />
29
<description>
30
Adds [param library] to the animation player, under the key [param name].
31
AnimationMixer has a global library by default with an empty string as key. For adding an animation to the global library:
32
[codeblocks]
33
[gdscript]
34
var global_library = mixer.get_animation_library("")
35
global_library.add_animation("animation_name", animation_resource)
36
[/gdscript]
37
[/codeblocks]
38
</description>
39
</method>
40
<method name="advance">
41
<return type="void" />
42
<param index="0" name="delta" type="float" />
43
<description>
44
Manually advance the animations by the specified time (in seconds).
45
</description>
46
</method>
47
<method name="capture">
48
<return type="void" />
49
<param index="0" name="name" type="StringName" />
50
<param index="1" name="duration" type="float" />
51
<param index="2" name="trans_type" type="int" enum="Tween.TransitionType" default="0" />
52
<param index="3" name="ease_type" type="int" enum="Tween.EaseType" default="0" />
53
<description>
54
If the animation track specified by [param name] has an option [constant Animation.UPDATE_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.
55
After this it will interpolate with current animation blending result during the playback process for the time specified by [param duration], working like a crossfade.
56
You can specify [param trans_type] as the curve for the interpolation. For better results, it may be appropriate to specify [constant Tween.TRANS_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 [constant Tween.TRANS_QUAD] for cases where the key value changes linearly.
57
</description>
58
</method>
59
<method name="clear_caches">
60
<return type="void" />
61
<description>
62
[AnimationMixer] caches animated nodes. It may not notice if a node disappears; [method clear_caches] forces it to update the cache again.
63
</description>
64
</method>
65
<method name="find_animation" qualifiers="const">
66
<return type="StringName" />
67
<param index="0" name="animation" type="Animation" />
68
<description>
69
Returns the key of [param animation] or an empty [StringName] if not found.
70
</description>
71
</method>
72
<method name="find_animation_library" qualifiers="const">
73
<return type="StringName" />
74
<param index="0" name="animation" type="Animation" />
75
<description>
76
Returns the key for the [AnimationLibrary] that contains [param animation] or an empty [StringName] if not found.
77
</description>
78
</method>
79
<method name="get_animation" qualifiers="const">
80
<return type="Animation" />
81
<param index="0" name="name" type="StringName" />
82
<description>
83
Returns the [Animation] with the key [param name]. If the animation does not exist, [code]null[/code] is returned and an error is logged.
84
</description>
85
</method>
86
<method name="get_animation_library" qualifiers="const">
87
<return type="AnimationLibrary" />
88
<param index="0" name="name" type="StringName" />
89
<description>
90
Returns the first [AnimationLibrary] with key [param name] or [code]null[/code] if not found.
91
To get the [AnimationMixer]'s global animation library, use [code]get_animation_library("")[/code].
92
</description>
93
</method>
94
<method name="get_animation_library_list" qualifiers="const">
95
<return type="StringName[]" />
96
<description>
97
Returns the list of stored library keys.
98
</description>
99
</method>
100
<method name="get_animation_list" qualifiers="const">
101
<return type="PackedStringArray" />
102
<description>
103
Returns the list of stored animation keys.
104
</description>
105
</method>
106
<method name="get_root_motion_position" qualifiers="const">
107
<return type="Vector3" />
108
<description>
109
Retrieve the motion delta of position with the [member root_motion_track] as a [Vector3] that can be used elsewhere.
110
If [member root_motion_track] is not a path to a track of type [constant Animation.TYPE_POSITION_3D], returns [code]Vector3(0, 0, 0)[/code].
111
See also [member root_motion_track] and [RootMotionView].
112
The most basic example is applying position to [CharacterBody3D]:
113
[codeblocks]
114
[gdscript]
115
var current_rotation
116
117
func _process(delta):
118
if Input.is_action_just_pressed("animate"):
119
current_rotation = get_quaternion()
120
state_machine.travel("Animate")
121
var velocity = current_rotation * animation_tree.get_root_motion_position() / delta
122
set_velocity(velocity)
123
move_and_slide()
124
[/gdscript]
125
[/codeblocks]
126
By using this in combination with [method get_root_motion_rotation_accumulator], you can apply the root motion position more correctly to account for the rotation of the node.
127
[codeblocks]
128
[gdscript]
129
func _process(delta):
130
if Input.is_action_just_pressed("animate"):
131
state_machine.travel("Animate")
132
set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
133
var velocity = (animation_tree.get_root_motion_rotation_accumulator().inverse() * get_quaternion()) * animation_tree.get_root_motion_position() / delta
134
set_velocity(velocity)
135
move_and_slide()
136
[/gdscript]
137
[/codeblocks]
138
If [member root_motion_local] is [code]true[/code], returns the pre-multiplied translation value with the inverted rotation.
139
In this case, the code can be written as follows:
140
[codeblocks]
141
[gdscript]
142
func _process(delta):
143
if Input.is_action_just_pressed("animate"):
144
state_machine.travel("Animate")
145
set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
146
var velocity = get_quaternion() * animation_tree.get_root_motion_position() / delta
147
set_velocity(velocity)
148
move_and_slide()
149
[/gdscript]
150
[/codeblocks]
151
</description>
152
</method>
153
<method name="get_root_motion_position_accumulator" qualifiers="const">
154
<return type="Vector3" />
155
<description>
156
Retrieve the blended value of the position tracks with the [member root_motion_track] as a [Vector3] that can be used elsewhere.
157
This is useful in cases where you want to respect the initial key values of the animation.
158
For example, if an animation with only one key [code]Vector3(0, 0, 0)[/code] is played in the previous frame and then an animation with only one key [code]Vector3(1, 0, 1)[/code] is played in the next frame, the difference can be calculated as follows:
159
[codeblocks]
160
[gdscript]
161
var prev_root_motion_position_accumulator
162
163
func _process(delta):
164
if Input.is_action_just_pressed("animate"):
165
state_machine.travel("Animate")
166
var current_root_motion_position_accumulator = animation_tree.get_root_motion_position_accumulator()
167
var difference = current_root_motion_position_accumulator - prev_root_motion_position_accumulator
168
prev_root_motion_position_accumulator = current_root_motion_position_accumulator
169
transform.origin += difference
170
[/gdscript]
171
[/codeblocks]
172
However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.
173
</description>
174
</method>
175
<method name="get_root_motion_rotation" qualifiers="const">
176
<return type="Quaternion" />
177
<description>
178
Retrieve the motion delta of rotation with the [member root_motion_track] as a [Quaternion] that can be used elsewhere.
179
If [member root_motion_track] is not a path to a track of type [constant Animation.TYPE_ROTATION_3D], returns [code]Quaternion(0, 0, 0, 1)[/code].
180
See also [member root_motion_track] and [RootMotionView].
181
The most basic example is applying rotation to [CharacterBody3D]:
182
[codeblocks]
183
[gdscript]
184
func _process(delta):
185
if Input.is_action_just_pressed("animate"):
186
state_machine.travel("Animate")
187
set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
188
[/gdscript]
189
[/codeblocks]
190
</description>
191
</method>
192
<method name="get_root_motion_rotation_accumulator" qualifiers="const">
193
<return type="Quaternion" />
194
<description>
195
Retrieve the blended value of the rotation tracks with the [member root_motion_track] as a [Quaternion] that can be used elsewhere.
196
This is necessary to apply the root motion position correctly, taking rotation into account. See also [method get_root_motion_position].
197
Also, this is useful in cases where you want to respect the initial key values of the animation.
198
For example, if an animation with only one key [code]Quaternion(0, 0, 0, 1)[/code] is played in the previous frame and then an animation with only one key [code]Quaternion(0, 0.707, 0, 0.707)[/code] is played in the next frame, the difference can be calculated as follows:
199
[codeblocks]
200
[gdscript]
201
var prev_root_motion_rotation_accumulator
202
203
func _process(delta):
204
if Input.is_action_just_pressed("animate"):
205
state_machine.travel("Animate")
206
var current_root_motion_rotation_accumulator = animation_tree.get_root_motion_rotation_accumulator()
207
var difference = prev_root_motion_rotation_accumulator.inverse() * current_root_motion_rotation_accumulator
208
prev_root_motion_rotation_accumulator = current_root_motion_rotation_accumulator
209
transform.basis *= Basis(difference)
210
[/gdscript]
211
[/codeblocks]
212
However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.
213
</description>
214
</method>
215
<method name="get_root_motion_scale" qualifiers="const">
216
<return type="Vector3" />
217
<description>
218
Retrieve the motion delta of scale with the [member root_motion_track] as a [Vector3] that can be used elsewhere.
219
If [member root_motion_track] is not a path to a track of type [constant Animation.TYPE_SCALE_3D], returns [code]Vector3(0, 0, 0)[/code].
220
See also [member root_motion_track] and [RootMotionView].
221
The most basic example is applying scale to [CharacterBody3D]:
222
[codeblocks]
223
[gdscript]
224
var current_scale = Vector3(1, 1, 1)
225
var scale_accum = Vector3(1, 1, 1)
226
227
func _process(delta):
228
if Input.is_action_just_pressed("animate"):
229
current_scale = get_scale()
230
scale_accum = Vector3(1, 1, 1)
231
state_machine.travel("Animate")
232
scale_accum += animation_tree.get_root_motion_scale()
233
set_scale(current_scale * scale_accum)
234
[/gdscript]
235
[/codeblocks]
236
</description>
237
</method>
238
<method name="get_root_motion_scale_accumulator" qualifiers="const">
239
<return type="Vector3" />
240
<description>
241
Retrieve the blended value of the scale tracks with the [member root_motion_track] as a [Vector3] that can be used elsewhere.
242
For example, if an animation with only one key [code]Vector3(1, 1, 1)[/code] is played in the previous frame and then an animation with only one key [code]Vector3(2, 2, 2)[/code] is played in the next frame, the difference can be calculated as follows:
243
[codeblocks]
244
[gdscript]
245
var prev_root_motion_scale_accumulator
246
247
func _process(delta):
248
if Input.is_action_just_pressed("animate"):
249
state_machine.travel("Animate")
250
var current_root_motion_scale_accumulator = animation_tree.get_root_motion_scale_accumulator()
251
var difference = current_root_motion_scale_accumulator - prev_root_motion_scale_accumulator
252
prev_root_motion_scale_accumulator = current_root_motion_scale_accumulator
253
transform.basis = transform.basis.scaled(difference)
254
[/gdscript]
255
[/codeblocks]
256
However, if the animation loops, an unintended discrete change may occur, so this is only useful for some simple use cases.
257
</description>
258
</method>
259
<method name="has_animation" qualifiers="const">
260
<return type="bool" />
261
<param index="0" name="name" type="StringName" />
262
<description>
263
Returns [code]true[/code] if the [AnimationMixer] stores an [Animation] with key [param name].
264
</description>
265
</method>
266
<method name="has_animation_library" qualifiers="const">
267
<return type="bool" />
268
<param index="0" name="name" type="StringName" />
269
<description>
270
Returns [code]true[/code] if the [AnimationMixer] stores an [AnimationLibrary] with key [param name].
271
</description>
272
</method>
273
<method name="remove_animation_library">
274
<return type="void" />
275
<param index="0" name="name" type="StringName" />
276
<description>
277
Removes the [AnimationLibrary] associated with the key [param name].
278
</description>
279
</method>
280
<method name="rename_animation_library">
281
<return type="void" />
282
<param index="0" name="name" type="StringName" />
283
<param index="1" name="newname" type="StringName" />
284
<description>
285
Moves the [AnimationLibrary] associated with the key [param name] to the key [param newname].
286
</description>
287
</method>
288
</methods>
289
<members>
290
<member name="active" type="bool" setter="set_active" getter="is_active" default="true">
291
If [code]true[/code], the [AnimationMixer] will be processing.
292
</member>
293
<member name="audio_max_polyphony" type="int" setter="set_audio_max_polyphony" getter="get_audio_max_polyphony" default="32">
294
The number of possible simultaneous sounds for each of the assigned AudioStreamPlayers.
295
For example, if this value is [code]32[/code] and the animation has two audio tracks, the two [AudioStreamPlayer]s assigned can play simultaneously up to [code]32[/code] voices each.
296
</member>
297
<member name="callback_mode_discrete" type="int" setter="set_callback_mode_discrete" getter="get_callback_mode_discrete" enum="AnimationMixer.AnimationCallbackModeDiscrete" default="1">
298
Ordinarily, tracks can be set to [constant Animation.UPDATE_DISCRETE] to update infrequently, usually when using nearest interpolation.
299
However, when blending with [constant Animation.UPDATE_CONTINUOUS] several results are considered. The [member callback_mode_discrete] specify it explicitly. See also [enum AnimationCallbackModeDiscrete].
300
To make the blended results look good, it is recommended to set this to [constant 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.
301
</member>
302
<member name="callback_mode_method" type="int" setter="set_callback_mode_method" getter="get_callback_mode_method" enum="AnimationMixer.AnimationCallbackModeMethod" default="0">
303
The call mode used for "Call Method" tracks.
304
</member>
305
<member name="callback_mode_process" type="int" setter="set_callback_mode_process" getter="get_callback_mode_process" enum="AnimationMixer.AnimationCallbackModeProcess" default="1">
306
The process notification in which to update animations.
307
</member>
308
<member name="deterministic" type="bool" setter="set_deterministic" getter="is_deterministic" default="false">
309
If [code]true[/code], the blending uses the deterministic algorithm. The total weight is not normalized and the result is accumulated with an initial value ([code]0[/code] or a [code]"RESET"[/code] animation if present).
310
This means that if the total amount of blending is [code]0.0[/code], the result is equal to the [code]"RESET"[/code] animation.
311
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.
312
If [code]false[/code], The blend does not use the deterministic algorithm. The total weight is normalized and always [code]1.0[/code]. If the number of tracks between the blended animations is different, nothing is done about the animation that is missing a track.
313
[b]Note:[/b] In [AnimationTree], the blending with [AnimationNodeAdd2], [AnimationNodeAdd3], [AnimationNodeSub2] or the weight greater than [code]1.0[/code] may produce unexpected results.
314
For example, if [AnimationNodeAdd2] blends two nodes with the amount [code]1.0[/code], then total weight is [code]2.0[/code] but it will be normalized to make the total amount [code]1.0[/code] and the result will be equal to [AnimationNodeBlend2] with the amount [code]0.5[/code].
315
</member>
316
<member name="reset_on_save" type="bool" setter="set_reset_on_save_enabled" getter="is_reset_on_save_enabled" default="true">
317
This is used by the editor. If set to [code]true[/code], the scene will be saved with the effects of the reset animation (the animation with the key [code]"RESET"[/code]) applied as if it had been seeked to time 0, with the editor keeping the values that the scene had before saving.
318
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.
319
</member>
320
<member name="root_motion_local" type="bool" setter="set_root_motion_local" getter="is_root_motion_local" default="false">
321
If [code]true[/code], [method get_root_motion_position] value is extracted as a local translation value before blending. In other words, it is treated like the translation is done after the rotation.
322
</member>
323
<member name="root_motion_track" type="NodePath" setter="set_root_motion_track" getter="get_root_motion_track" default="NodePath(&quot;&quot;)">
324
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 [member root_motion_track] uses the same format as [method Animation.track_set_path], but note that a bone must be specified.
325
If the track has type [constant Animation.TYPE_POSITION_3D], [constant Animation.TYPE_ROTATION_3D], or [constant Animation.TYPE_SCALE_3D] the transformation will be canceled visually, and the animation will appear to stay in place. See also [method get_root_motion_position], [method get_root_motion_rotation], [method get_root_motion_scale], and [RootMotionView].
326
</member>
327
<member name="root_node" type="NodePath" setter="set_root_node" getter="get_root_node" default="NodePath(&quot;..&quot;)">
328
The node which node path references will travel from.
329
</member>
330
</members>
331
<signals>
332
<signal name="animation_finished">
333
<param index="0" name="anim_name" type="StringName" />
334
<description>
335
Notifies when an animation finished playing.
336
[b]Note:[/b] This signal is not emitted if an animation is looping.
337
</description>
338
</signal>
339
<signal name="animation_libraries_updated">
340
<description>
341
Notifies when the animation libraries have changed.
342
</description>
343
</signal>
344
<signal name="animation_list_changed">
345
<description>
346
Notifies when an animation list is changed.
347
</description>
348
</signal>
349
<signal name="animation_started">
350
<param index="0" name="anim_name" type="StringName" />
351
<description>
352
Notifies when an animation starts playing.
353
[b]Note:[/b] This signal is not emitted if an animation is looping.
354
</description>
355
</signal>
356
<signal name="caches_cleared">
357
<description>
358
Notifies when the caches have been cleared, either automatically, or manually via [method clear_caches].
359
</description>
360
</signal>
361
<signal name="mixer_applied">
362
<description>
363
Notifies when the blending result related have been applied to the target objects.
364
</description>
365
</signal>
366
<signal name="mixer_updated">
367
<description>
368
Notifies when the property related process have been updated.
369
</description>
370
</signal>
371
</signals>
372
<constants>
373
<constant name="ANIMATION_CALLBACK_MODE_PROCESS_PHYSICS" value="0" enum="AnimationCallbackModeProcess">
374
Process animation during physics frames (see [constant Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS]). This is especially useful when animating physics bodies.
375
</constant>
376
<constant name="ANIMATION_CALLBACK_MODE_PROCESS_IDLE" value="1" enum="AnimationCallbackModeProcess">
377
Process animation during process frames (see [constant Node.NOTIFICATION_INTERNAL_PROCESS]).
378
</constant>
379
<constant name="ANIMATION_CALLBACK_MODE_PROCESS_MANUAL" value="2" enum="AnimationCallbackModeProcess">
380
Do not process animation. Use [method advance] to process the animation manually.
381
</constant>
382
<constant name="ANIMATION_CALLBACK_MODE_METHOD_DEFERRED" value="0" enum="AnimationCallbackModeMethod">
383
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.
384
</constant>
385
<constant name="ANIMATION_CALLBACK_MODE_METHOD_IMMEDIATE" value="1" enum="AnimationCallbackModeMethod">
386
Make method calls immediately when reached in the animation.
387
</constant>
388
<constant name="ANIMATION_CALLBACK_MODE_DISCRETE_DOMINANT" value="0" enum="AnimationCallbackModeDiscrete">
389
An [constant Animation.UPDATE_DISCRETE] track value takes precedence when blending [constant Animation.UPDATE_CONTINUOUS] or [constant Animation.UPDATE_CAPTURE] track values and [constant Animation.UPDATE_DISCRETE] track values.
390
</constant>
391
<constant name="ANIMATION_CALLBACK_MODE_DISCRETE_RECESSIVE" value="1" enum="AnimationCallbackModeDiscrete">
392
An [constant Animation.UPDATE_CONTINUOUS] or [constant Animation.UPDATE_CAPTURE] track value takes precedence when blending the [constant Animation.UPDATE_CONTINUOUS] or [constant Animation.UPDATE_CAPTURE] track values and the [constant Animation.UPDATE_DISCRETE] track values. This is the default behavior for [AnimationPlayer].
393
</constant>
394
<constant name="ANIMATION_CALLBACK_MODE_DISCRETE_FORCE_CONTINUOUS" value="2" enum="AnimationCallbackModeDiscrete">
395
Always treat the [constant Animation.UPDATE_DISCRETE] track value as [constant Animation.UPDATE_CONTINUOUS] with [constant Animation.INTERPOLATION_NEAREST]. This is the default behavior for [AnimationTree].
396
If a value track has un-interpolatable type key values, it is internally converted to use [constant ANIMATION_CALLBACK_MODE_DISCRETE_RECESSIVE] with [constant Animation.UPDATE_DISCRETE].
397
Un-interpolatable type list:
398
- [constant @GlobalScope.TYPE_NIL]
399
- [constant @GlobalScope.TYPE_NODE_PATH]
400
- [constant @GlobalScope.TYPE_RID]
401
- [constant @GlobalScope.TYPE_OBJECT]
402
- [constant @GlobalScope.TYPE_CALLABLE]
403
- [constant @GlobalScope.TYPE_SIGNAL]
404
- [constant @GlobalScope.TYPE_DICTIONARY]
405
- [constant @GlobalScope.TYPE_PACKED_BYTE_ARRAY]
406
[constant @GlobalScope.TYPE_BOOL] and [constant @GlobalScope.TYPE_INT] are treated as [constant @GlobalScope.TYPE_FLOAT] during blending and rounded when the result is retrieved.
407
It is same for arrays and vectors with them such as [constant @GlobalScope.TYPE_PACKED_INT32_ARRAY] or [constant @GlobalScope.TYPE_VECTOR2I], they are treated as [constant @GlobalScope.TYPE_PACKED_FLOAT32_ARRAY] or [constant @GlobalScope.TYPE_VECTOR2]. Also note that for arrays, the size is also interpolated.
408
[constant @GlobalScope.TYPE_STRING] and [constant @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.
409
</constant>
410
</constants>
411
</class>
412
413