← Pixel Dreamer Studio

Play a 2D sprite sheet effect once and remove it, even if its animation loops

Turn Loop off on the sprite's own copy of the SpriteFrames, then free it on animation_finished.

animation_finished is only sent by animations with Loop off, and a new SpriteFrames animation starts with Loop on. In our Godot 4.7 test a looping effect connected to queue_free sent animation_looped 4 times in 2 seconds, animation_finished 0 times, and stayed on screen. With Loop off it was removed after one play. The script turns Loop off on its own copy, so other sprites using the same SpriteFrames keep looping.

The code

Put the script on an AnimatedSprite2D with your effect's SpriteFrames and animation set, save it as a scene, and instance it where the hit happens. It plays once and removes itself.

extends AnimatedSprite2D
## Play a sprite sheet effect once, then remove it, even if its animation is set
## to Loop. Other sprites that share the same SpriteFrames keep looping.


func _ready() -> void:
	sprite_frames = sprite_frames.duplicate()  # our own copy, so the change below stays on this sprite
	sprite_frames.set_animation_loop(animation, false)  # a looping animation never sends animation_finished
	animation_finished.connect(queue_free)
	play()

What we measured

An animation of 8 frames at 16 fps (0.5 s), run for 2 real seconds. Two runs: the same counts, and removal times of 0.44 and 0.48 s.

Why it happens

A looping animation has no last frame to stop on, so Godot sends animation_looped each time it wraps, and never animation_finished. Loop is stored in the SpriteFrames, a resource every sprite using it shares, so switching it off there would also stop your looping torches and campfires. duplicate() gives the effect its own copy first.

What to change

The same for particles: remove one-shot particles when finished. Building the frames from a sheet without the empty cells: SpriteFrames from a grid.

Ready-made 2D effects: HD VFX Sprite Sheets Vol 1 has 106 animated effects as transparent PNG sprite sheets for 2D engines, Godot 2D included.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: HD VFX Sprite Sheets Vol 1 has 106 animated effects as transparent PNG sprite sheets for 2D engines, Godot 2D included.

More how-tos for HD VFX Sprite Sheets Vol 1: GPUParticles2D not showing in Godot 4 · Transparent PNGs without a dark outline

More how-tos: Play, stop and remove effects