- Home /
Is it better to use ParticleSystems on one GameObject OR instantiate ParticleSystems?
So usually I attach all particle systems(like 1st particle system triggers when taking damage, second triggers when healing and etc) to one GameObject. I thoughts its okay for me but with time number of particle systems on some of the GameObjects increased up to 10 and more. Then my friend recommended me another solution, without putting particle systems directly into gameobjects: he offered to make Prefabs of all ParticleSystems and then just attach them to your script and play manually, when needed(code below):
public ParticleSystem[] Effects;
public void TakeDamage(){
Effects[0].Play();
}
public void HealDamage(){
Effects[3].Play();
}
I found this option very useful and comfortable. My other friend recommended me other way: Instantiating the particle systems:
public ParticleSystem[] Effects;
public void TakeDamage(){
Instantiate(Effects[0], transform.position, Quaternion.identity);
}
There's a question: Which option is the most optimized? Will be glad to read your suggestions for even better options, than are even lighter than the options I listed above. Thanks! (I use 2D Environment, if you are interested)
Answer by dumoulinantoine · Jun 11, 2021 at 05:19 PM
The first is ofc more faster than Instantiating on runtime. This is a general thought, but it's even more true for particle systems. If you wanna add many particles systems, you should look about Object pooling. Like that you could instantiate as many as you want on runtime. But if you don't have many and it's only one or 2 instance, then instantiate still good for better code lisibility.