- Home /
 
pooling particle system
Hi, i wondering how to make a particle system pooling? since my game use same particle system (eplosion) multiple times, so maybe there is a way to reuse the particle system and not destroying and instantiate a new one every time.
right now i using this but i have no idea how to change it to do pooling
 private ParticleSystem instantiate(ParticleSystem prefab, Vector3 position)
     {
 
         ParticleSystem newParticleSystem = Instantiate(
             prefab,
             position,
             Quaternion.identity
             ) as ParticleSystem;
 
         //make sure it will be destroyed
         Destroy(
             newParticleSystem.gameObject,
             newParticleSystem.startLifetime
             );
 
         return newParticleSystem;
     }
 
              You could try modifying one of these scripts for particle systems. $$anonymous$$aybe just change GameObject to ParticleSystem, or attach your particle system to a game object?
Answer by Forsh · Feb 05, 2016 at 04:39 PM
I've been trying to get this working too lately but have hit a snag. I used ParticleSystemDestroyer.cs as the basis for a new class ParticlePoolManager.cs, which I attach to the particle systems (and remove the original). Instead of destroying particle systems it uses a PoolManager object I created and put in the scene, which stops them and shoves them into a List. On requesting a new instance of that particular particle (via the PoolManager) it will check the pool first and use that instance if one exists, and re-positions/restarts the PS.
This works for non-nested particle systems but fails when there are more than one within the prefab being pooled.
I would be interested to hear if anyone else has had success recursing through nested particle systems and pooling them as a single object to be reused.
Your answer