Emit more particles during the particles lifetime

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By akuramuzda

I’m trying to make a jump/land particles for a platform game, but I’m facing a problem trying to emit particles. Just setting particles.emitting=true/false doesn’t work properly because when you set emitting=true and still have active particles this will not emit new particles. particles.restart() doesn’t work either because it erases all particles and only after that emits new particles. Instantiating new particle nodes on every jump doesn’t seem to be very efficient either.

:bust_in_silhouette: Reply From: Inces

Most efficient option is to build a node childing few instances of the same particles, governing queue of particle emission.
Take a look at 6:24 of this tutorial:

I had this issue and some things have changed in Godot 4, here is an updated version of that code from the video for anyone else coming across this!

extends Node2D

@export var particle: PackedScene
@export var queue_count: int = 8

var index = 0

func _ready():
	for _i in range(queue_count):
		add_child(particle.instantiate())
		
func get_next_particle():
	return get_child(index)
	
func trigger():
	get_next_particle().restart()
	index = (index + 1) % queue_count