AnimationNodeStateMachine
Inherits: AnimationRootNode < AnimationNode < Resource < Shared < Object
A state machine with multiple AnimationRootNodes, used by AnimationTree.
Description
Section titled “Description”Contains multiple AnimationRootNodes representing animation states, connected in a graph. State transitions can be configured to happen automatically or via code, using a shortest-path algorithm. Retrieve the AnimationNodeStateMachinePlayback object from the AnimationTree node to control it programmatically.
use actor::AnimationTree as animation_tree : AnimationTree
fn _ready() void { state_machine : AnimationNodeStateMachinePlayback = animation_tree.get("parameters/playback") as AnimationNodeStateMachinePlayback state_machine.travel("some_state")}Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| bool | allow_transition_to_self | false |
| bool | reset_ends | false |
| AnimationNodeStateMachine.StateMachineType | state_machine_type | 0 |
Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | add_node(name, node, position) |
| void | add_transition(from, to, transition) |
| Vector2 | get_graph_offset() |
| AnimationNode | get_node(name) |
[]StringName | get_node_list() |
| StringName | get_node_name(node) |
| Vector2 | get_node_position(name) |
| AnimationNodeStateMachineTransition | get_transition(idx) |
| int | get_transition_count() |
| StringName | get_transition_from(idx) |
| StringName | get_transition_to(idx) |
| bool | has_node(name) |
| bool | has_transition(from, to) |
| void | remove_node(name) |
| void | remove_transition(from, to) |
| void | remove_transition_by_index(idx) |
| void | rename_node(name, new_name) |
| void | replace_node(name, node) |
| void | set_graph_offset(offset) |
| void | set_node_position(name, position) |
Enumerations and constants
Section titled “Enumerations and constants”enum StateMachineType
Section titled “enum StateMachineType”- STATE_MACHINE_TYPE_ROOT =
0— Seeking to the beginning is treated as playing from the start state. Transition to the end state is treated as exiting the state machine.
- STATE_MACHINE_TYPE_NESTED =
1— Seeking to the beginning is treated as seeking to the beginning of the animation in the current state. Transition to the end state, or the absence of transitions in each state, is treated as exiting the state machine.
- STATE_MACHINE_TYPE_GROUPED =
2— This is a grouped state machine that can be controlled from a parent state machine. It does not work independently. There must be a state machine withstate_machine_typeofSTATE_MACHINE_TYPE_ROOTorSTATE_MACHINE_TYPE_NESTEDin the parent or ancestor.
Property descriptions
Section titled “Property descriptions”allow_transition_to_self
Section titled “allow_transition_to_self”bool allow_transition_to_self = false
Setter/getter: set_allow_transition_to_self(), is_allow_transition_to_self()
If true, allows teleport to the self state with AnimationNodeStateMachinePlayback.travel(). When the reset option is enabled in AnimationNodeStateMachinePlayback.travel(), the animation is restarted. If false, nothing happens on the teleportation to the self state.
reset_ends
Section titled “reset_ends”bool reset_ends = false
Setter/getter: set_reset_ends(), are_ends_reset()
If true, treat the cross-fade to the start and end nodes as a blend with the RESET animation.
In most cases, when additional cross-fades are performed in the parent AnimationNode of the state machine, setting this property to false and matching the cross-fade time of the parent AnimationNode and the state machine’s start node and end node gives good results.
state_machine_type
Section titled “state_machine_type”AnimationNodeStateMachine.StateMachineType state_machine_type = 0
Setter/getter: set_state_machine_type(), get_state_machine_type()
This property can define the process of transitions for different use cases. See also StateMachineType.
Method descriptions
Section titled “Method descriptions”add_node
Section titled “add_node”void add_node(name: StringName, node: AnimationNode, position: Vector2 = Vector2(0, 0))
Adds a new animation node to the graph. The position is used for display in the editor.
add_transition
Section titled “add_transition”void add_transition(from: StringName, to: StringName, transition: AnimationNodeStateMachineTransition)
Adds a transition between the given animation nodes.
get_graph_offset
Section titled “get_graph_offset”Vector2 get_graph_offset() const
Returns the draw offset of the graph. Used for display in the editor.
get_node
Section titled “get_node”AnimationNode get_node(name: StringName) const
Returns the animation node with the given name.
get_node_list
Section titled “get_node_list”[]StringName get_node_list() const
Returns a list containing the names of all animation nodes in this state machine.
get_node_name
Section titled “get_node_name”StringName get_node_name(node: AnimationNode) const
Returns the given animation node’s name.
get_node_position
Section titled “get_node_position”Vector2 get_node_position(name: StringName) const
Returns the given animation node’s coordinates. Used for display in the editor.
get_transition
Section titled “get_transition”AnimationNodeStateMachineTransition get_transition(idx: int) const
Returns the given transition.
get_transition_count
Section titled “get_transition_count”int get_transition_count() const
Returns the number of connections in the graph.
get_transition_from
Section titled “get_transition_from”StringName get_transition_from(idx: int) const
Returns the given transition’s start node.
get_transition_to
Section titled “get_transition_to”StringName get_transition_to(idx: int) const
Returns the given transition’s end node.
has_node
Section titled “has_node”bool has_node(name: StringName) const
Returns true if the graph contains the given animation node.
has_transition
Section titled “has_transition”bool has_transition(from: StringName, to: StringName) const
Returns true if there is a transition between the given animation nodes.
remove_node
Section titled “remove_node”void remove_node(name: StringName)
Deletes the given animation node from the graph.
remove_transition
Section titled “remove_transition”void remove_transition(from: StringName, to: StringName)
Deletes the transition between the two specified animation nodes.
remove_transition_by_index
Section titled “remove_transition_by_index”void remove_transition_by_index(idx: int)
Deletes the given transition by index.
rename_node
Section titled “rename_node”void rename_node(name: StringName, new_name: StringName)
Renames the given animation node.
replace_node
Section titled “replace_node”void replace_node(name: StringName, node: AnimationNode)
Replaces the given animation node with a new animation node.
set_graph_offset
Section titled “set_graph_offset”void set_graph_offset(offset: Vector2)
Sets the draw offset of the graph. Used for display in the editor.
set_node_position
Section titled “set_node_position”void set_node_position(name: StringName, position: Vector2)
Sets the animation node’s coordinates. Used for display in the editor.