ParticleSystem. Stopping Emission

This is for the old Particle System method, This has bugged me for years, Over various Unity versions

I look online and see the answer to this question and a lot of people saying, I think the docs also say this.

var ps = GetComponent();
ps.Stop(); ← Does not work, Even the Unity documentation says this should work

or

ParticleSystem.EmissionModule em = ps.emission;
em.enabled = false; ← also Does not work

  1. what actually works, as in stopping the particle system from emitting is
    ParticleSystem.EmissionModule em = ps.emission;
    em.rateOverTime = 0;
    em.rateOverDistance = 0;

So I’m just curious why do people recommend 2 methods that don’t actually work?
Scratching my head here

You probably just have a bug.

All three methods work perfectly.

All three methods do COMPLETELY different things that cause a particle system to stop.

Enclosed is full package, open the scene, press PLAY.

Here is the script. Try it yourself.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// @kurtdekker - all of these methods work just fine but ALL are different things.

public class ZedzPS : MonoBehaviour
{
    [Header( "Drag a ParticleSystem into each of these!")]
    public ParticleSystem ps1;
    public ParticleSystem ps2;
    public ParticleSystem ps3;

    IEnumerator Start ()
    {
        yield return new WaitForSeconds( 2.0f);

        // method 1: Stops the entire particle simulator
        ps1.Stop();

        yield return new WaitForSeconds( 2.0f);

        // method 2: disables the emission module
        {
            ParticleSystem.EmissionModule em = ps2.emission;
            em.enabled = false;
        }

        yield return new WaitForSeconds( 2.0f);

        // method 3: sets distance and time rates to zero
        {
            ParticleSystem.EmissionModule em = ps3.emission;
            em.rateOverTime = 0;
            em.rateOverDistance = 0;
        }
    }
}

9742927–1393930–ZedsPS.unitypackage (12.3 KB)

1 Like

Sorry for not replying earlier. For some reason it takes hours before my threads show up for other people (as in I make a post, come back 8 hours later and it has zero views, its only the next day or so then it has ~40 views or something), so I’ve learn to wait before checking my thread.

I will check out your package (Later today, just some things to do this morning)

You’ve gone above the call of duty mate by making that.
I’m curious to see if it works, like I said I’ve noticed this in multiple versions of Unity for years.
Normally I would assume I’m just doing it wrong as its such an obvious bug that surely 100s of ppl have noticed it before, but its so simple that I don’t see how I’m doing it wrong

OK tested, your code works as it should.
But rechecked mine, no nothing it just ignores Stop()

public void Update()
    {
        for (int i = onCollisionDisableEmission.Count - 1; i >= 0; --i)
        {
            ParticleSystem ps = onCollisionDisableEmission[i].GetComponent<ParticleSystem>();
            if (ps)
            {
                print( ps.particleCount );
            }
        }
    }

elsewhere

for ( int i = onCollisionDisableEmission.Count-1; i>=0; --i )
                {
                    ParticleSystem ps = onCollisionDisableEmission[i].GetComponent<ParticleSystem>();
                    if ( ps )
                    {
                        ParticleSystem.EmissionModule em = ps.emission;
                        em.rateOverTime = 0;
                        em.rateOverDistance = 0;
                    //    em.enabled = false;
                    //    ps.Stop();
                        print( "Stopping");
                    }
                }

Stopping
18
18
18
18
18
18
18
18
18
18
18
18
17
17
17
17

for ( int i = onCollisionDisableEmission.Count-1; i>=0; --i )
                {
                    ParticleSystem ps = onCollisionDisableEmission[i].GetComponent<ParticleSystem>();
                    if ( ps )
                    {
                   //     ParticleSystem.EmissionModule em = ps.emission;
                    //    em.rateOverTime = 0;
                     //   em.rateOverDistance = 0;
                    //    em.enabled = false;
                        ps.Stop();
                        print( "Stopping");
                    }
                }

Stopping
20
20
20
20
20
20
20
21
21
21
21
21
21
21
22
22
22

Stranger yet

if I go
em.enabled = false;
and view the particle system in the inspector, the emission module will become unticked
but it still happily continues emitting particles

the only way to stop emission is to do

  • em.rateOverTime = 0
  • em.rateOverDistance = 0;

Its been like this for years on multiple unity versions thus the issue must be me but I’m dammed if I know why.