Performance: Particle lifetime and speed
This affects how fast particles are created, updated, and removed, impacting frame rate and smoothness of animations.
Jump into concepts and practice - no test required
var particle = new Particle(); particle.lifetime = 2f; // reasonable lifetime particle.speed = 20f; // moderate speed // limit max particles and reuse with pooling
var particle = new Particle(); particle.lifetime = 10f; // very long lifetime particle.speed = 100f; // very high speed // many particles created without limit
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Long lifetime + high speed | Many active particles updated each frame | N/A | High GPU overdraw and fill rate | [X] Bad |
| Short lifetime + moderate speed | Fewer active particles, efficient updates | N/A | Lower GPU overdraw | [OK] Good |
startLifetime property of a ParticleSystem control in Unity?startLifetimestartLifetime property sets the duration each particle exists after being emitted.startSpeed is inside the main module, accessed as particleSystem.main.startSpeed.startSpeed is not a direct property of ParticleSystem. particleSystem.setSpeed(5); uses a non-existent method.var ps = GetComponent<ParticleSystem>(); var main = ps.main; main.startLifetime = 2f; main.startSpeed = 3f; Debug.Log(main.startLifetime + ", " + main.startSpeed);What will be printed in the console?
startLifetime and startSpeed are floats. Assigning 2f and 3f sets them to 2.0 and 3.0 internally.var ps = GetComponent<ParticleSystem>(); ps.startLifetime = 4f;What is the main problem?
startLifetime is inside the main module, so it cannot be set directly on ps.var main = ps.main; main.startLifetime = 4f;. Direct assignment causes error.startLifetime = 3f is correct.velocityOverLifetime module with a curve, not just startSpeed.startLifetime = 3f and set startSpeed = 6f only sets constant speed 6, not increasing. Set startLifetime = 6f and startSpeed = 2f has wrong lifetime. Set startLifetime = 3f and change speed in Update() manually is inefficient and unnecessary.