Performance: Particle System component
This affects the rendering performance and frame rate by controlling how many particles are drawn and updated each frame.
Jump into concepts and practice - no test required
var ps = GetComponent<ParticleSystem>();
var main = ps.main;
main.maxParticles = 500;
ps.Play();var ps = GetComponent<ParticleSystem>();
var main = ps.main;
main.maxParticles = 10000;
ps.Play();| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| High maxParticles (10000) | N/A | N/A | High GPU load, many draw calls | [X] Bad |
| Moderate maxParticles (500) | N/A | N/A | Lower GPU load, fewer draw calls | [OK] Good |
Particle System component in Unity?ps in a C# script?Play() to start emitting particles.Start(), Begin(), and Run() do not exist for Particle System and will cause errors.ParticleSystem ps = GetComponent<ParticleSystem>();
ps.Stop();
if (ps.isPlaying)
Debug.Log("Playing");
else
Debug.Log("Stopped");ps.Stop(); then checks if it is playing using ps.isPlaying.ps.isPlaying will be false, so the else branch runs and prints "Stopped".ParticleSystem ps = GetComponent<ParticleSystem>(); ps.startColor = Color.red;
startColor property is deprecated in recent Unity versions; color must be set via the main module.var main = ps.main; main.startColor = Color.red; to change particle color properly.Update()?GetKeyDown detects the press moment, so we start playing particles then.