How do I "queue_free" but, only after my animation has fully played.

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

The script I’m using to play the Animation and to it free from the memory looks like this:

func dead():
is_dead = true
velocity = Vector2(0, 0)

However, it is freed from the memory before it can play the animation.
How can I implement this, but have it still play my full animation before it’s removed?

:bust_in_silhouette: Reply From: i_love_godot

I would probably wait for the animation_finished signal to be emitted using yield:

func dead():
    isdead = true
    velocity = Vector2(0, 0)
    yield($AnimatedSprite, "animation_finished")

I haven’t tested that, but it’s similar to what I do with other nodes. Hope this helps :slight_smile:

They could actually just turn off the looping function on the animated sprite.

ItsYoBoi | 2019-12-09 03:28

From the OP’s post, I don’t think looping is the issue. They want to remove the node, but only after the animation has had time to complete. Even with looping turned off, the call to queue_free will execute before the animation has played.

i_love_godot | 2019-12-09 03:34

:bust_in_silhouette: Reply From: rustyStriker

You can add a function track which calls certain functions at certain times(and can pass variables), you use it with the little + sign in the top left of the little animation box.

simply add that track to your scene and add a new key using right click on the track and you are free to go(or at least queue for it)

:bust_in_silhouette: Reply From: ItsYoBoi

I can answer this for you. You don’t even have to write any code for it. If you go to the animated sprite and click on the “Dead” category you have for your character, you should see a “loop” option. If you simply turn that off, the animation will only play once.