auto destruct a particle system.

I’ve been using this code I found from other answers of the same question, and it’s generally worked out rather well.

function Update ()
{
 	if ( particleSystem != null && particleSystem.particleCount == 0 )
	{
        Destroy ( gameObject );
    }
}

I just attach that to the particle system in question and usually have had no issues. But I’ve tried to attach it to an explosion I’ve made, and for some reason the explosion now doesn’t show up at all, it just instantly get’s destroyed!

Anyone have any thoughts?

Try this:

private var ps : ParticleSystem;
     
    ////////////////////////////////////////////////////////////////
     
    function Start () {
             ps = GetComponent(ParticleSystem);
    }
     
    function Update () {
        if(ps)
        {
           if(!ps.IsAlive())
           {
             Destroy(gameObject);
           }
        }
    }

maybe at the beginning partial count is 0, it take some time to start …

I have a particle prefab and attached this script, it works.