Spawning, and removing a node after play_bwckwatds() animation ended

Godot Version

4.2.1 (macOS)

Question

I have been struggling with this for a day and I think that there needs to be a simple way of doing this I missing here.

what I want to do

Create a effect that there ground is exploding when player steps on it, and play animation of it imploding inside again after he steps out of the tile, and repeat the cycle for the next tile.

how am I trying to do this:

I create a node in main tree that gets the signal when player changes coords on the tilemap. I instantiate the PackedScene with Spire2D and animation player on his position, start the explosion animation and put the reference to that Scene inside a dictionary. If there is already animation playing for the player I will pause() this animation and play it backwards, which looks exactly as I would like but…

the problem

I can’t clear the instance once it played. First thing I tried is to add a “call method track” and call a function that will remove the scene from the tree and queue_free it. But this will be called instantly not letting the animation play:


and add a flag for second animation play to actually remove the node on second play through.
It kinda works but it will call the function instantly. Not allowing the animation to finish playing.

I figured out maybe I should put the function in “call method track” at the beginning of the track as it is playing backwards (duh). But still the same issue.

not sure why it will call the method instantly when playing backwards.
I also tried to use the “animation_finished” signal on the animation player but it seems this is not emitting when I try to connect to it.

The animation_finished signal should be called even if the animation is played backwards, this should just work:

$AnimationPlayer.finished.connect(queue_free)

If you are having issues the call method hack you started can be used:

You could set two “call method” on the track: at the start and the end

The methods:

var animation_finished_once: bool = false
func on_animation_start():
	if animation_finished_once:
		queue_free()

func on_animation_finished():
	animation_finished_once = true

That way the on_animation_start() will only free the object if the animation finished at least once

1 Like

I tried once more with .animation_finished and it worked. No idea what I done wrong the first time. Thank you for your help :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.