AnimatedSprite2D not queue_freeing

Godot Version

4.2.1

Question

I’m trying to get an AnimatedSprite2D to queue_free when it has finished its animation, but I am clearly missing something.

func _ready():
var sprite = AnimatedSprite2D.new()
sprite.sprite_frames = load(“res://spriteframes.tres”)
sprite.position = Vector2(100,100)
sprite.play()
sprite.animation_finished.connect(queue_free.bind(sprite))
self.add_child(sprite)

The animation loads and plays but doesn’t free

Thanks

I don’t know which node this script is declared on, but you are calling that node’s queue_free() function (instead of your sprite’s) !

try something like

sprite.animation_finished.connect(func():
    sprite.queue_free())
1 Like

Just figured it out. I had to disable looping in the sprite frames. As the animation wasn’t ever finished it didn’t send the signal. Thanks

2 Likes