0 votes

Here's a paste of the code. The rpint statements are there to help me debug.

func explode():
print("explode called")
if $AnimatedSprite.is_playing():
    print("still playing")
    print($AnimatedSprite.animation)
    yield(get_node("AnimatedSprite"), "animation_finished")
print("finished")
queue_free()

In the above code, "finished" is only printed if the animation is actively playing at the point it reaches the if conditional (if the current frame < final frame). In that case, the yield works as expected. It waits, then continues to the print statement and the queue_free.

If the animation has already finished (current frame = last frame) by the time it reaches the $AnimatedSprite.is_playing conditional, it still returns true (the print statements both show) but the yield doesn't return.

So it appears as if the animationfinished signal is not being called on an animation that has already finished, even though isplaying is still considered true.

Any idea what I'm doing wrong here?

in Engine by (78 points)

1 Answer

+1 vote
Best answer

You should connect the animation_finished signal of the animation player to a function to do what you're trying to achieve. I think is_playing will be false only if you call the stop() method so that is no use for you in this case.

Also make sure your animation is not a loop.

by (380 points)
selected by

Ah I see! I misunderstood how is_playing was called. I implemented your suggestion, and it all works. Thank you!

Glad to help! Good luck!

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.