Recycling particle system

I am implementing an object pool using this implementation.
It’s already working fine with prefabs but I don’t know how to handle the recycling of particles system.

In my game when the main character picks stars I create a particle system by doing:

GameObject explosion = Instantiate (explosionPrefab) as GameObject;
explosion.transform.position = this.transform.position;

and after doing the emission it gets deleted because the Autodestruct flag is on.

I was looking for a method or someway to know when the particle emission finishes to call:

ObjectPoolManager.DestroyPooled( explosion );

Any ideas?

There are three ways you could go about this depending on how you are using the object the particles are attached to:

  1. If you are keep the object after particles are executed, then just check the “One Shot” box in the particle options. It will set off the particles at one time, like an explosion, and not repeat it.

  2. If you are destroying the object after use, then it should destroy the particles with it, which automatically solves your issue. If youre not, label the particle object attached to the main object and send a Destroy() to that object.

  3. Or you could take this code and attach it to the particle object and sync the amount of time the particle emits to the timer that will destroy the object:

    var timeOut : int = 1.0;
    var detachChildren : boolean = false;

//Set timer to destroy
function Awake ()
{
Invoke (“DestroyNow”, timeOut);
}

//Destroy Object attached
function DestroyNow ()
{
if (detachChildren) {
transform.DetachChildren ();
}
DestroyObject(gameObject);

This will automatically delete the particle object when you please.

Hope this helps!