- Home /
Best way to use particle systems for explosions?
So I was initially instantiating a new particle system for every explosion but they weren't auto-destroying, which surprised me. So I did some research and found a post which suggested that it was preferable to just use one particle system and move it around for each explosion. Unfortunately when I move it, it moves the other explosions along with it, so that's not so great.
Basically should I be moving a single system around and if so, how do I keep it from erasing the previous explosion, or should I just create and destroy new particle systems every time? What's the generally preferable way to do this?
Answer by jacobschellenberg · Nov 11, 2013 at 08:34 PM
Destroying and instantiating could be slow and lead to undesirable effects... I would suggest having the particle system already attached to the objects, and just turn on/off the emission when needed.
Something to this effect. It's kind of pseudo-ish
float particleDurationTimer= 3.0f;
float timer;
if(objectDestroyed == true){
timer += Time.deltaTime;
myObject.GetComponent<ParticleSystem>().enableEmission = true;
if(timer > particleDurationTimer){
myObject.GetComponent<ParticleSystem>().enableEmission = false;
}
}
I appreciate the help, and that was more or less my first approach, but I can't seem to get a persistent particle system to effectively manage multiple explosions, so i'm just creating and destroying them like mad for now :)
Well, if it isn't a problem now and it isn't causing performance issues, then by all means destroy away. haha Code first, optimize later.