How to stop or dispose of multiple particleSystem(s)

Hello BJS Community,
Hope yours are all well.

I’m willing to feature some work from the community featured in the ‘playground examples’ to make a Season’s event in my scene.
I have been looking at the 3 links below from the playground examples for #particles and can easily twist and integrate them.

https://playground.babylonjs.com/#10MC9H#0

https://playground.babylonjs.com/#2A4NUR#2

https://playground.babylonjs.com/#2A4NUR#7

However, there’s one thing I did not manage although it sounds simple. I cannot stop the (multiple) particleSystems without getting an error or a freeze. If I give an Id or name to all and then go through the length or index (for ~200 particleSystems), i get a freeze.

Can anyone indicate me (from the 3 playgrounds above) how to declare/build a function that would start/stop (or eventually dispose) of all these particles on trigger (and then without freezing the scene)?

Thanks in advance,

The main issue is you should not create that many particle systems :slight_smile: You should at least reuse the one out of screens.

The best strategy would be to keep track of them in an array so on stop / dispose you can simply go over the array and dispose them. You could first stop them in a frame and dispose in subsequent one if it is too much of a perf hit.

Thanks,
I was afraid I would get this kind of answer. I actually tried the array approach but this is where I got the freeze when attempting to go through the array (I didn’t try leave a frame or anything, just let it right through). It was working with a lower number (~10) but clearly not with 200.
I also guess some of these playground examples look nice just like that. Some you would probably not want to integrate in your scene. On the other hand, it’s for making ‘faen’ fireworks. :partying_face:
We know how tricky this is. I’ll see if I can keep with the spirit of it but make it differently (with far less particleSystems). Well, thanks for the advise anyway. I was hoping it was just me being unable to make the correct declaration.

Ok Apologies,
Sometimes it helps just to ask someone because you are going the wrong way. :wink: You can sense when you are going the wrong way… it’s generally when you need to use too much code. :nerd_face:So, I went back to it just once more and there it was (in 5mins and just a few lines of code). This version works with 20 or 200 or more particleSystem.
Simple, straight forward… I guess still not recommended to use as such. But, yes, it works.
https://playground.babylonjs.com/#2A4NUR#72
Press 1 or 7 to start or stop the particles (I left 1 system active on stop just so to see that it works)

I love it GG pressing 1 is so damn pretty !!! @PirateJC

1 Like

Just to make this clear, the original idea and code is not mine. (see link above).
The only purpose here - in this update of mine - is to show how to interact with the particleSystems created. (by giving them a name and ID and index for particleSystem(s)) In this single playground example, they are 20, but there could be more. And there will be more in my scene event.

I also loved the original idea and is why, with this small adding of mine that makes it useable, it will be integrated in my Xmas event (actually it already is :smiley:

2 Likes