In Godot 4, I'm trying to spawn particles and detach them from the object so that they continue even after queue_free() but this isn't working.

I don't want to wait around for the particles to finish before I remove the object. Do I need to just wait for one frame to pass or something? Wondering what to put maybe an await?

What happens with the code above is the queue_free() also removes the particles before they are done.

I thought set_as_top_level would reparent the object to the scene root. Maybe it does but I need to wait a frame?

I tried this but it doesn't help:

i guess i could make a singleton that just looks for signals and triggers all the particles but that feels wrong - want my particles in the object that spawns them if possible.

I guess I can hide the body and wait until the particles are done then queue free.

If the particle emitter is a child of the object, then if you remove the object, all children will also be freed.

Probably what you could do is use remove_child() and add_child() to more the particle system to the parent object when the current object is deleted.

var particles = $CPUParticles3D
remove_child(particles)
particles.position = position
get_parent().add_child(particles)
call_deferred("queue_free")