How to get current node in AnimationTree StateMachine on lowest level

Godot Version

Godot v4.2


I am using an AnimationTree StateMachine for a 2D platformer character as a means of future-proofing for when we add lots of animations and handling the logic for that. Right now it consists of two sub StateMachines for handling grounded and mid-air animations. I would like for the ability to check in-code for the current node, but my current method is returning the name of the subtrees and I don’t know how to go a level deeper.

This is what the OnGround tree looks like. I would like for the ability to check for when the tree is currently in the “turn” node. Using $AnimationTree.get(“parameters/playback”).get_current_node() returns “OnGround”, the name of the subtree.

First time posting so if more information would help let me know

You’ll need to get the AnimationNodeStateMachinePlayback from the AnimationNodeStateMachine you want to get the information from. For the OnGround state machine it may be something like $AnimationTree.get("parameters/OnGround/playback").get_current_node() The Parameters group in the inspector of the AnimationTree will give you the correct property path.

1 Like