Is `travel()` async or blocking?

Godot Version

4.5

Question

I have this AnimationTree

It works as expected. Idle2 and Sleep are looping animations. Their outgoing transitions are `enabled` (hence white) and I also set `break_loop_at_end` to true.

So we run:
func _ready() → void:
anim_tree.active = true
state_machine.start(“Idle2”)

and we end up at Idle2 node. Since it’s looping and the outgoing transition is enabled, we basically stay there. Next we call change the state of our dog to SLEEP which calls:

func handle_sleep(delta: float) → void:
if last_state != current_state:
print(“ENTERING SLEEP”)
state_machine.travel(“Sleep”)
print("Travel path: ", state_machine.get_travel_path())
last_state = current_state

. The travel call travels Idle2 → LieStart → SleepStart → Sleep. This works fine but the above code prints an empty travel path. Note that this code only gets executed once.

Now if I move print("Travel path: ", state_machine.get_travel_path())outsie the if (which means we call it 60 times per second since this function gets called in `_physics_process()`, then we see:

Travel path: [&“LieStart”, &“SleepStart”, &“Sleep”]

I read the code above as sequential. Isn’t it sequential? If it is, how come the travel path is still zero? Is `travel()` maybe async or something? If it is, how do I see that in the ref docs? AnimationNodeStateMachinePlayback — Godot Engine (stable) documentation in English

Thanks

You can say that the call is “async” in broad sense. It sets the travel state of the object and then further per-frame processing advances/manages that state. The path will not be assigned until the next AnimationNodeStateMachinePlayback::process() call happens internally. In other words, there may be one frame delay before get_travel_path() can return the set path.

thanks for the explanation and especialyl the source link. Makes way more sense now.

1 Like