The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+2 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

in Engine by (45 points)

2 Answers

–2 votes

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.

by (695 points)

Okay thanks. I will look into it.

Read more about yield here: Coroutines with yield

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.

+2 votes

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: https://www.reddit.com/r/godot/comments/7lsrga/animationtreeplayer_detecting_when_an_animation/

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)

by (164 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.