+1 vote

I am using AnimationPlayer and AninmationState and want to play a "die" animation, and THEN queue_free() but I cant make it work. My first guess was to use "yield", but I dont know how:

if (health <= 0):
   # yield...

My second guess was to wait for AnimationPlayer to emit a signal, but it does not emit anything:

func _on_AnimationPlayer_animation_finished(anim_name):
    if (anim_name === "Die"):
Godot version 3.4
in Engine by (13 points)

2 Answers

+1 vote

Yeah, I had that problem lately too. I hope new Godot will finally provide animation_finished signals for animationTree. What I did to get around it was getting animation.length from animationplayer and yielding


But this sollution is not perfect. Yield has another flaw in Godot 3.2, it processess in pause. So someone might cheese your game by pausing on animations :)

by (7,743 points)
0 votes

Maybe this is not the best way to achieve it, but you can call a function when a specific animation finished by calling a method in the last frame in the AnimationPlayer node.
When the AnimationTree play's the animation in the last frame, the function will be called.

I used C#, but the idea is the same, here are the steps in images:
step 1
step 2
Choose the node with your script attached, in my case is the Player's node.
step 3
in my case I'm using c#, but the idea is the same, create a function to call at the end of an animation.
we create the function (step 4)
After writing our function to call, then we go back to Godot editor and at the last frame we insert the key, but this case in the Player Functions' Track
inserting the function key
selecting our method/function
enter image description here

We're done! Test it and I hope you like it. One more thing, we can use the same method for different animations, just insert the new track in the other animations, insert the key in the last frame and select your method/function.

by (14 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.