#How do you handle VFX (trigger Particle Systems + Sound)?

12 messages · Page 1 of 1 (latest)

sour bough
#

Hey,

just wanted to know how you handle triggering multiple particle effects + sound for your game when an effect needs more than 1 single particle system.
I do it in the following way (but I'm not sure if there's maybe a better solution?

So, I've made an FX-Scene per effect where a Node2D is a root and several AudioStreamPlayers and ParticleSystems can be a child. A script at the root iterates over all children and starts each on _ready()::

Node2D (+ Script)
   - AudioStreamPlayer_explosion
   - CpuParticle2D_explosion_1
   - CpuParticle2D_shockwave_2
   - CpuParticle2D_sparkles_3

The function to start all particle systems is for example:

func get_particle_systems():
    for child in get_children():
        if child.is_class("CPUParticles2D"):
            child.emitting = true

Since Particle Systems don't free themselves, my script also checks if any particle system is still emitting or if any sound is still playing. If not, it kills the whole thing:

func _process(_delta):
    
    if started:
        var isAnyoneStillEmitting = false
        for particle in particleSystems:
            if particle.emitting:
                isAnyoneStillEmitting = true
        
        for child in get_children():
            if child.is_class("AudioStreamPlayer2D"):
                if child.playing:
                    isAnyoneStillEmitting = true
        
        if not isAnyoneStillEmitting:
            queue_free()

I just want to know: Are you doing it like me (starting and also killing the particle systems/sounds)? Is there maybe a better solution?

fluid cargo
#

Thats one way to do it for sure. Another way could be that you emit a signal from the root, passing in the root as a parameter. Then in each particle system, you can have a function that starts the particles emission if the root that got passed is the parent of the particles. Then, most of the time, you know more or less how long a particle system will need to be on screen. So, you can use a timer to queue free the entire parent, which should free it's children if I'm not mistaken.

#

Let me check the documentation to see what signals a particle system has, if any.

#

So ya, I looked at the docs and couldn't find any signal.

#

I did find these two things though which might help with some of this in the meantime

#

Towards the bottom of that post, someone has a formula for handling freeing of the particles

#

And I found this as well. TLDR, a finished signal is coming in 4.2 🤞

#

I haven't gotten to particles for my game yet but this is a very good question and very good information for me moving forward. Thank you for bringing it up and sharing.

marble basin
#

For this case, I'd just create a timer and once I know all the particles are done and also the sound is done, I'd free the node with its timeout signal.
The problem is that Id need to manually know how much the timer needs to be set beforehand and assign its wait time value as an export var. Or I could just assign a general wait time of, I dont know, 5 s since I dont really need to be that precise in order to free the node, as long as it is not visible.

#

And because I know these kind of vfx are short enough, so 5 s as a default wait time value seems reasonable for me