Working Around One-Shot GPUParticles2D Emitter Slowdown
I’ve got a couple of one-shot GPUParticles2D emitters in my Godot game, and they have a habit of causing slowdown when they’re emitted for the first time. For a while I tolerated this, but it’s got to the point where gameplay was being affected, and this had to be dealt with.
I had some success removing that slowdown using a variant of the technique documented here. Basically, you fire the emitter within the _ready() function, wait a single frame, then hide the emitter:
func _ready():
pop_emitter.emitting = true
await get_tree().process_frame
pop_emitter.visible = false
This does mean you’ll need to set the emitter visibility to true when you want to fire it for real:
func emit_for_real():
pop_emitter.visible = true
pop_emitter.emitting = true
Based on my experience, the order is pretty important. The emitter needs to be visible while it’s emitting in order for the material to load. But it seems like a single frame is enough for that to happen. The technique also works if the emitter is a fair distance from the camera. And in that case, you probably don’t need to hide the emitter at all.