0
0
Unityframework~8 mins

Color and size over lifetime in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: Color and size over lifetime
MEDIUM IMPACT
This affects the rendering performance by controlling how particle colors and sizes change over their lifetime, impacting GPU workload and frame rate.
Animating particle color and size over their lifetime in a Unity particle system
Unity
var ps = GetComponent<ParticleSystem>();
var col = ps.colorOverLifetime;
col.enabled = true;
col.color = new ParticleSystem.MinMaxGradient(Color.white);
var size = ps.sizeOverLifetime;
size.enabled = true;
size.size = new ParticleSystem.MinMaxCurve(1f);
Using simple constant colors and sizes reduces GPU calculations and improves frame rate.
📈 Performance GainReduces GPU cost, improving interaction responsiveness (INP).
Animating particle color and size over their lifetime in a Unity particle system
Unity
var ps = GetComponent<ParticleSystem>();
var col = ps.colorOverLifetime;
col.enabled = true;
col.color = new ParticleSystem.MinMaxGradient(
    new Gradient() {
        colorKeys = new GradientColorKey[] {
            new GradientColorKey(Color.red, 0f),
            new GradientColorKey(Color.green, 0.5f),
            new GradientColorKey(Color.blue, 1f)
        },
        alphaKeys = new GradientAlphaKey[] {
            new GradientAlphaKey(1f, 0f),
            new GradientAlphaKey(0f, 1f)
        }
    }
);
var size = ps.sizeOverLifetime;
size.enabled = true;
size.size = new ParticleSystem.MinMaxCurve(1f, AnimationCurve.EaseInOut(0f, 0f, 1f, 1f));
Using complex gradients and animation curves for color and size causes the GPU to perform more calculations per particle each frame.
📉 Performance CostIncreases GPU workload, potentially dropping frame rates on lower-end devices.
Performance Comparison
PatternGPU CalculationsShader ComplexityFrame Rate ImpactVerdict
Complex gradients and curvesHigh per particleHighCan cause frame drops on low-end GPUs[X] Bad
Simple constant colors and sizesLow per particleLowSmooth frame rates even on weaker devices[OK] Good
Rendering Pipeline
Color and size over lifetime settings are processed by the GPU during particle rendering. Complex gradients and curves increase shader complexity, affecting the Paint and Composite stages.
Paint
Composite
⚠️ BottleneckPaint stage due to complex shader calculations per particle
Core Web Vital Affected
INP
This affects the rendering performance by controlling how particle colors and sizes change over their lifetime, impacting GPU workload and frame rate.
Optimization Tips
1Simplify color gradients to reduce GPU shader complexity.
2Prefer constant size values over complex curves for better performance.
3Use Unity Profiler to monitor GPU cost of particle effects.
Performance Quiz - 3 Questions
Test your performance knowledge
How does using complex color gradients over particle lifetime affect performance?
AIncreases GPU workload and can reduce frame rate
BHas no impact on performance
CImproves CPU performance
DReduces memory usage
DevTools: Unity Profiler
How to check: Open Unity Profiler, select GPU module, run scene with particles, observe GPU usage and frame time spikes related to particle rendering.
What to look for: High GPU time in particle rendering indicates costly color/size over lifetime settings.