Changing color and size over lifetime helps make effects look alive and natural. It adds smooth changes as things grow or fade.
0
0
Color and size over lifetime in Unity
Introduction
When making a fire particle that changes from bright yellow to dark smoke
When creating a magic spell that grows bigger and changes color as it fades
When animating a bubble that grows and becomes transparent before popping
When designing rain drops that shrink and disappear as they fall
Syntax
Unity
ParticleSystem.MainModule main = particleSystem.main; main.startColor = new ParticleSystem.MinMaxGradient(Color.white, Color.red); main.startSize = new ParticleSystem.MinMaxCurve(1f, 3f); ParticleSystem.ColorOverLifetimeModule colorOverLifetime = particleSystem.colorOverLifetime; colorOverLifetime.enabled = true; colorOverLifetime.color = new ParticleSystem.MinMaxGradient( new Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.red, 1f) }, alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(0f, 1f) } } ); ParticleSystem.SizeOverLifetimeModule sizeOverLifetime = particleSystem.sizeOverLifetime; sizeOverLifetime.enabled = true; sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f));
Use colorOverLifetime.enabled = true to activate color changes over time.
Gradients define how color and transparency change from start (0) to end (1) of particle life.
Examples
This sets all particles to stay red during their lifetime.
Unity
var colorOverLifetime = particleSystem.colorOverLifetime; colorOverLifetime.enabled = true; colorOverLifetime.color = Color.red;
This makes particles grow from half size to double size over their life.
Unity
var sizeOverLifetime = particleSystem.sizeOverLifetime; sizeOverLifetime.enabled = true; sizeOverLifetime.size = AnimationCurve.Linear(0f, 0.5f, 1f, 2f);
This smoothly changes particle color from yellow to black and fades out transparency.
Unity
Gradient gradient = new Gradient();
gradient.colorKeys = new GradientColorKey[] {
new GradientColorKey(Color.yellow, 0f),
new GradientColorKey(Color.black, 1f)
};
gradient.alphaKeys = new GradientAlphaKey[] {
new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(0f, 1f)
};
var colorOverLifetime = particleSystem.colorOverLifetime;
colorOverLifetime.enabled = true;
colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient);Sample Program
This script changes particles from white to blue and shrinks them to zero size as they live.
Unity
using UnityEngine; public class ColorSizeOverLifetime : MonoBehaviour { public ParticleSystem particleSystem; void Start() { var main = particleSystem.main; main.startColor = Color.white; main.startSize = 1f; var colorOverLifetime = particleSystem.colorOverLifetime; colorOverLifetime.enabled = true; Gradient gradient = new Gradient(); gradient.colorKeys = new GradientColorKey[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.blue, 1f) }; gradient.alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(0f, 1f) }; colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient); var sizeOverLifetime = particleSystem.sizeOverLifetime; sizeOverLifetime.enabled = true; sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f)); } }
OutputSuccess
Important Notes
Always enable the colorOverLifetime and sizeOverLifetime modules to see changes.
Use gradients to control smooth color and transparency changes.
Animation curves let you customize size changes over time easily.
Summary
Color and size over lifetime make particles look natural and dynamic.
Enable and set gradients or curves to control these changes.
Use this to create effects like fading, growing, or color shifting.