[Godot 3.1] How to transit to next state in Animation State Machine?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By icqqq

I hav made a state machine in Animation State Machine but don’t know how to set the condition to next state

The state machine is inside a animation tree node, so I need to retrieve the state machine first?

Any ideas?


:bust_in_silhouette: Reply From: Xrayez

Assuming AnimationNodeStateMachine is assigned as a root of animation tree:

# Retrieve state machine controller
var playback = $animation_tree.get("parameters/playback")

# Make sure to `Start` a state machine before any transition can occur

# ... code to change state here ...

if walking:
    # Transition to a new state according to defined transition graph

if jumping:

Animation state machine transition graph

You can stop the animation state machine simply with:


See the docs for additional info.
Also the official blog post about the new animation system.