Particle lifetime and speed control how long particles last and how fast they move. This helps make effects like fire, smoke, or magic look real and interesting.
Particle lifetime and speed in Unity
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Unity
var main = particleSystem.main; main.startLifetime = 2.0f; // seconds main.startSpeed = 5.0f; // units per second
You access lifetime and speed through the main module of the ParticleSystem.
Both startLifetime and startSpeed can be set to a constant or a range.
Examples
Unity
var main = particleSystem.main; main.startLifetime = 3.0f; main.startSpeed = 4.0f;
Unity
var main = particleSystem.main; main.startLifetime = new ParticleSystem.MinMaxCurve(1.0f, 5.0f); main.startSpeed = new ParticleSystem.MinMaxCurve(2.0f, 6.0f);
Unity
var main = particleSystem.main; main.startLifetime = 0.5f; main.startSpeed = 10.0f;
Sample Program
This script sets the particle system so each particle lasts 2.5 seconds and moves at speed 3 when the game starts.
Unity
using UnityEngine; public class ParticleControl : MonoBehaviour { public ParticleSystem particleSystem; void Start() { var main = particleSystem.main; main.startLifetime = 2.5f; // particles live 2.5 seconds main.startSpeed = 3.0f; // particles move at speed 3 } }
Important Notes
Changing lifetime affects how long particles stay visible before disappearing.
Speed controls how fast particles move away from their source.
You can use ranges to add variety and make effects look more natural.
Summary
Particle lifetime controls how long particles last.
Particle speed controls how fast particles move.
Both are set through the particle system's main module.
Practice
1. What does the
startLifetime property of a ParticleSystem control in Unity?easy
Solution
Step 1: Understand the meaning of
ThestartLifetimestartLifetimeproperty sets the duration each particle exists after being emitted.Step 2: Compare with other properties
Speed controls movement, color controls appearance, size controls scale. Only lifetime controls duration.Final Answer:
How long each particle stays alive before disappearing -> Option AQuick Check:
Particle lifetime = duration alive [OK]
Hint: Lifetime means how long particles live before vanishing [OK]
Common Mistakes:
- Confusing lifetime with speed
- Thinking lifetime affects color or size
- Mixing up startLifetime with emission rate
2. Which of the following is the correct way to set the particle speed to 5 in a Unity ParticleSystem script?
easy
Solution
Step 1: Recall ParticleSystem API structure
In Unity,startSpeedis inside themainmodule, accessed asparticleSystem.main.startSpeed.Step 2: Check syntax correctness
Options A and B are incorrect becausestartSpeedis not a direct property of ParticleSystem. particleSystem.setSpeed(5); uses a non-existent method.Final Answer:
particleSystem.main.startSpeed = 5f; -> Option DQuick Check:
Use main module to set startSpeed [OK]
Hint: Use particleSystem.main.startSpeed to set speed [OK]
Common Mistakes:
- Trying to set startSpeed directly on particleSystem
- Using incorrect method names
- Forgetting to use the main module
3. Consider this Unity C# code snippet:
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?
medium
Solution
Step 1: Understand property types and output
ThestartLifetimeandstartSpeedare floats. Assigning 2f and 3f sets them to 2.0 and 3.0 internally.Step 2: Check Debug.Log output format
Logging floats with string concatenation prints "2, 3" because ToString() on whole number floats omits the decimal.Final Answer:
2, 3 -> Option CQuick Check:
Whole number floats print without decimals [OK]
Hint: Whole number floats print without decimal in Debug.Log [OK]
Common Mistakes:
- Expecting decimal output like 2.0, 3.0
- Thinking 'f' suffix prints in output
- Assuming assignment causes error
4. This code tries to set particle lifetime but causes an error:
var ps = GetComponent<ParticleSystem>(); ps.startLifetime = 4f;What is the main problem?
medium
Solution
Step 1: Understand ParticleSystem property access
In Unity,startLifetimeis inside themainmodule, so it cannot be set directly onps.Step 2: Identify correct way to set lifetime
Correct syntax isvar main = ps.main; main.startLifetime = 4f;. Direct assignment causes error.Final Answer:
startLifetime must be set via the main module, not directly -> Option AQuick Check:
Use main module to set startLifetime [OK]
Hint: Always set startLifetime via particleSystem.main [OK]
Common Mistakes:
- Trying to set startLifetime directly on ParticleSystem
- Assuming startLifetime is read-only
- Confusing missing component with syntax error
5. You want to create a particle effect where particles live for 3 seconds and move faster over time, starting at speed 2 and increasing to 6. Which approach correctly sets this behavior in Unity?
hard
Solution
Step 1: Set particle lifetime correctly
Particles should live 3 seconds, sostartLifetime = 3fis correct.Step 2: Use velocityOverLifetime for speed change
To increase speed over time from 2 to 6, use thevelocityOverLifetimemodule with a curve, not juststartSpeed.Step 3: Evaluate other options
SetstartLifetime = 3fand setstartSpeed = 6fonly sets constant speed 6, not increasing. SetstartLifetime = 6fandstartSpeed = 2fhas wrong lifetime. SetstartLifetime = 3fand change speed in Update() manually is inefficient and unnecessary.Final Answer:
Set startLifetime = 3f and use velocityOverLifetime module to increase speed from 2 to 6 -> Option BQuick Check:
Use velocityOverLifetime for speed changes over time [OK]
Hint: Use velocityOverLifetime to change speed during particle life [OK]
Common Mistakes:
- Setting only startSpeed for changing speed over time
- Confusing lifetime and speed values
- Trying to update speed manually every frame
