0 votes

HI everyone, I currently have these lines of code:

if hit == true:
    state_machine.travel("death")
    queue_free()

My objective is to finish the animation of a certain node before removing it from a parent node. My problem is, statemachine.travel("death"), and queuefree() is being executed simultaneously. Is there a way to determine if the animationtree's finished playing the animation? Thanks

asked Jan 13 in Engine by ddarkmoto (35 points)

1 Answer

+1 vote

You can do that by using yield keyword:

if hit == true:
    state_machine.travel("death")
    yield(your_animation_node, animation_finished_signal_name)
    queue_free()

yield stops executing the function until the given signal is emitted. If the signal returns some value, var value = yield(args) can be used to get it.

answered Jan 13 by JulioYagami (600 points)

Okay thanks. I will look into it.

Read more about yield here: Coroutines with yield

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.