Dispose a particle system

How do i dispose a particle system?

https://www.babylonjs-playground.com/#1VGT5D#19

ParticleHelper.CreateAsync returns a Promise, not the system.

Use:

    new BABYLON.ParticleHelper.CreateAsync("sun", scene).then((systems) => {
        //sphere.position.set(-2,0,0);
        systems.systems.forEach((system) => system.emitter = sphere);
        systems.start();
        //systems.dispose();
    });

https://www.babylonjs-playground.com/#1VGT5D#21

2 Likes

I don’t understand.
How can i dispose outside that function at a later time?

You can assign it to a global variable and use that.

var mysystem;

    new BABYLON.ParticleHelper.CreateAsync("sun", scene).then((systems) => {
        systems.systems.forEach((system) => system.emitter = sphere);
        systems.start();
        mysystem = systems;
    });

//sometime later...
mysystem.dispose()
1 Like

That’s it, thank you very much! :smiley:

Hi there?
Did that work for you?
If I use it that way , outSide the {} it gives me an Error.

But if I use mysystem.dispose(); inside the { } it works just fine…
…

hello @Laureano
i think your error is maybe

  1. var mysystem ; (it is undefined)
  2. and create Particle , set up mysystem = particle
  3. Then an error, because the wait callback was not called or not called on success (When your logic calls before mysystem.dispose() is finished) you call mysystem.dispose() This may be an undefined error.
    and using parameter systemsed(it is variable) instead of systems

https://www.babylonjs-playground.com/#1VGT5D#54

thanks a lot for your adice!
Your answered helped me a lot…
I just realized that I was calling it to fast, and couldn’t find the partcles. like they wern’t created yet.

So I found a solution doing something like this.

if (systemsed!=undefined){
        systemsed.dispose();
    }
2 Likes