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

1 Like

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: