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.
- A new SpriteFrames:
get_animation_loop("default")is true. - Loop on, animation_finished connected to queue_free: animation_finished 0 times, animation_looped 4 times, still there after 2 s.
- Loop off: animation_finished once, removed at 0.44 s and 0.48 s.
- The script on looping SpriteFrames: the same, removed after one play. Another sprite sharing those SpriteFrames kept looping, 4 loops in 2 s, and the shared animation still had Loop on.
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
- For effects you reuse from a pool, hide the sprite on animation_finished instead of freeing it, and call play() next time.
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
- An aura that comes back when the buff comes back
- A spawned effect that appears exactly where you hit
- Draw the hit effect over what it hit
- Remove a one-shot particle effect when it ends
- Fade out and stop looping particles
- Spawn a hit effect facing the surface
- Hit sparks from a pool of emitters
- Changing one particle effect's color changes all of them
- Particles that play the same way every time
- Freeze particles in mid-air
- Running dust and landing puffs
- Particles left behind by a moving object
- 2D particles follow the player or stay behind
- Footstep particles that match the ground
- A level up effect that plays while paused
- Hide particle effects far from the camera
- Death particles disappear when the enemy is freed
- Remove all particles at once
- Tire smoke that only shows when the car drifts
- Sprite sheet frames without the empty cells
- Sprite sheet frames without lines from the next cell