Animationtree: Cheking if animation is finished playing

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

HI everyone, I currently have these lines of code:

if hit == true:"death")

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

:bust_in_silhouette: Reply From: JulioYagami

You can do that by using yield keyword:

if hit == true:"death")
    yield(your_animation_node, animation_finished_signal_name)

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.

Okay thanks. I will look into it.

ddarkmoto | 2020-01-14 07:07

Read more about yield here: Coroutines with yield

JulioYagami | 2020-01-14 19:55

You mean the AnimationPlayer, used by AnimationTree? Nope, it doesn’t return any signals when used in an AnimationTree. And AnimationTree doesn’t have signals for that.
Also is_playing() doesn’t work in AnimationTree, since it always returns TRUE.
So i think there are a lot of issues to be fixed in AnimationTree.

Migoun | 2020-04-02 16:56

:bust_in_silhouette: Reply From: pox

Kinda late but I found a solution, It’s a bit bothersome but it works

You can use a “Call Method Track” in every animation
Add a key at the end, select a method with a string parameter and write the animation name in the key “Args” section to pass it

I got it from this reddit post: Reddit - Dive into anything

Since I only needed it for a few animations it wasn’t that bad, but between this and other common issues like only having boolean conditionals or not being able to edit the animation speed directly without a blend node… it really screams the need for an update of the animation tree

Also, a simple solution for your problem would be to directly choose the queue_free() method in the call method track (search it at the top)