queue_free() frees a node and all its children. If the sparks are a child of the enemy, they go with it: in our Godot 4.7 test, a burst started under the enemy just before queue_free() showed 0 lit points. Add the effect to the level instead, at the enemy's position, then free the enemy. With the script below, 423 to 446 lit points showed 0.2 seconds later, and the burst removed itself when it finished.

The code
Attach this to the enemy and call die() when its health reaches 0. The burst is built in code so the example is complete. With your own effect scene, instantiate it and add it to the level the same way.
extends Node3D
## Put this on an enemy. die() leaves a burst of sparks behind and removes the enemy.
## The sparks go into the level, not under the enemy, so queue_free() does not take them along.
func die() -> void:
var fx := GPUParticles3D.new()
fx.amount = 40
fx.lifetime = 0.8
fx.one_shot = true
fx.explosiveness = 1.0
var m := ParticleProcessMaterial.new()
m.direction = Vector3.UP
m.spread = 70.0
m.initial_velocity_min = 3.0
m.initial_velocity_max = 5.0
m.gravity = Vector3(0, -9.8, 0)
fx.process_material = m
var mat := StandardMaterial3D.new()
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
mat.billboard_mode = BaseMaterial3D.BILLBOARD_PARTICLES
mat.albedo_color = Color(1, 0.55, 0.2)
var q := QuadMesh.new()
q.size = Vector2(0.12, 0.12)
q.material = mat
fx.draw_pass_1 = q
fx.finished.connect(fx.queue_free) # the burst removes itself when its last spark is gone
get_tree().current_scene.add_child(fx) # the fix: in the level, not under this enemy
fx.global_position = global_position
fx.restart() # after add_child, so finished fires
queue_free()
What we measured
An enemy at a height of 1 m, killed 0.2 seconds after it was added. We counted lit points 0.2 seconds after the kill, and the emitters left in the level 1.5 seconds after it. Two runs of each.
- The script: 423 to 446 lit points. 0 emitters left, because the burst freed itself.
- The burst as a child of the enemy: 0 lit points.
- The same with
top_levelon: still 0. top_level stops a child from following its parent's transform, but it is still freed with the parent. - Moving the burst into the level with
reparent()just beforequeue_free(): 479 to 481 lit points, 0 emitters left.
If the effect is already in the enemy scene
fx.reparent(get_tree().current_scene) moves it into the level and keeps it where it is. Connect its finished signal to queue_free too, or the used emitter stays in the level.
What to change
amount,spread,initial_velocity_min,initial_velocity_max: the size of the burst.get_tree().current_scene: any node that outlives the enemy works, such as a node that holds all effects.
Why restart() comes after add_child(): remove one-shot particles when finished. Many hits a second: reuse a pool of emitters.
Tested in Godot 4.7 with the Compatibility renderer.
More how-tos: Play, stop and remove effects
- 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
- Remove all particles at once