Unity Lighting and Visual Effects
Lighting Modes
Unity provides three light modes controlling how illumination is calculated.
Realtime Lights
- Calculate lighting every frame at runtime
- Allow dynamic changes to intensity, color, position
- Cast shadows up to Shadow Distance
- Contribute only direct lighting by default (no bounced light)
- Higher runtime cost, especially in complex scenes or low-end hardware
- Best for: dynamic objects, flickering effects, moving light sources
Baked Lights
- Calculations performed in the Unity Editor and saved as lighting data to disk
- At runtime, Unity loads pre-computed data instead of calculating dynamically
- Bake both direct and indirect lighting into lightmaps
- Store information in Light Probes for moving objects
- Cannot modify light properties at runtime; do not illuminate dynamic GameObjects
- No specular contributions
- Best for: static scenery, complex indirect lighting, performance-critical scenarios
Mixed Lights
- Combine baked indirect lighting with real-time direct lighting
- Behavior depends on the Lighting Mode setting in the Lighting window
- Cast real-time shadows (not baked soft shadows)
- Can change properties at runtime (affects real-time component only)
- Always more expensive than fully baked lighting
- Best for: dynamic shadows with baked background lighting
Important: All baked/mixed modes require Baked Global Illumination enabled. Without it, Mixed and Baked lights behave as Realtime.
Light Types
Directional Light
- Located infinitely far away, emits light in one direction
- Parallel rays, no distance-based intensity falloff
- Simulates sun/moon; every new scene includes one by default
- Links to procedural sky system; rotate to create time-of-day effects
Point Light
- Located at a point, emits in all directions equally
- Intensity follows inverse square law (diminishes with distance squared)
- Use for lamps, explosions, local illumination
Spot Light
- Located at a point, emits in a cone shape
- Adjustable cone angle; light diminishes at edges (penumbra)
- Wider angles create larger fade areas
- Use for flashlights, headlights, searchlights
Area Light
- Defined by a rectangle or disc; emits uniformly across surface
- Follows inverse square law; produces soft, subtle shading
- Bake-only -- not available at runtime
- Use for street lights, realistic interior lighting
Global Illumination
Global illumination (GI) simulates how light bounces between surfaces, producing realistic indirect lighting.
Baked GI
- Pre-computes indirect lighting into lightmaps using the Progressive Lightmapper (CPU or GPU)
- Results stored in lightmap textures and Light Probes
- Configure in the Lighting window under Bake settings
- GPU Progressive Lightmapper offers faster bake times with configurable tile sizes
Environment Lighting
Three ambient light sources configured in the Lighting window Environment tab:
- Skybox: Uses skybox material colors for ambient light from different angles
- Gradient: Separate sky, horizon, and ground colors with smooth blending
- Color: Uniform ambient light across the scene
Intensity Multiplier (0-8, default 1) controls ambient brightness.
Environment Reflections
- Source: Skybox or custom Cubemap/RenderTexture
- Configurable resolution, compression, intensity multiplier
- Bounces setting controls reflection evaluation iterations between objects
Light Probes and Adaptive Probe Volumes
Light Probes
- Capture lighting information in empty space throughout a scene
- At runtime, indirect lighting for dynamic GameObjects is approximated using nearest probes
- Provide indirect bounced light for moving objects and LOD system support
- Must be manually placed using Light Probe Groups
- Store baked lighting information; work with both direct and indirect lighting
Adaptive Probe Volumes (APV)
APV is the modern replacement for manual Light Probe placement in URP:
- Automated probe placement -- eliminates manual Light Probe Group positioning
- Per-pixel lighting -- superior quality compared to per-object approaches
- Scene baking -- bake multiple scenes together using Baking Sets
- Runtime adjustments -- Lighting Scenarios and sky occlusion for dynamic changes
- Large-world support -- streaming data for expansive open-world environments
- Data flexibility -- loading from AssetBundles or Addressables
- Configurable probe density and volume size with visualization tools
Reflection Probes
Capture a spherical view of surroundings as a cubemap for reflective materials.
Types
| Type |
Description |
| Baked |
Captures static GameObjects only; best performance |
| Custom |
Allows dynamic object capture with custom textures |
| Realtime |
Updates during gameplay; configurable refresh mode |
Key Properties
- Importance: Rendering priority when multiple probes overlap
- Intensity: Texture brightness in shader calculations
- Box Projection: Enables projection mapping for interiors (requires URP config)
- Box Size/Offset: World-space bounding box for reflection contribution
- Blend Distance: Blending distance for deferred probes
Realtime Options
- Refresh Mode: On Awake, Every Frame, or Via Scripting
- Time Slicing: All Faces At Once, Individual Faces, No Time Slicing
Particle System vs VFX Graph
| Feature |
Particle System |
VFX Graph |
| Simulation |
CPU-based |
GPU-based |
| Particle count |
Thousands |
Millions |
| Render pipeline |
All pipelines |
URP/HDRP only |
| Authoring |
Inspector modules |
Node-based graph editor |
| Physics |
Built-in collision |
Custom collision blocks |
| Scripting |
Full C# API |
Event-based C# API |
| Sub-emitters |
Native support |
GPU Event contexts |
| Best for |
Small/medium effects, mobile |
Large-scale effects, high-end |
Decision Guide:
- Use Particle System for mobile targets, simple effects, when you need full CPU-side scripting control, or when targeting the Built-in Render Pipeline
- Use VFX Graph for massive particle counts, GPU-driven simulations, complex node-based authoring, or high-end platforms with URP/HDRP
Particle System Modules
| Module |
Purpose |
| Main |
Initial state: lifetime, speed, size, gravity, simulation space |
| Emission |
Rate and timing of particle spawns |
| Shape |
Volume/surface for emission and start velocity direction |
| Velocity over Lifetime |
Modify movement over particle age |
| Noise |
Turbulence for organic, chaotic motion |
| Limit Velocity over Lifetime |
Natural deceleration |
| Force over Lifetime |
Simulated physics forces |
| Inherit Velocity |
Sub-emitter particles match parent velocity |
| Lifetime by Emitter Speed |
Adjust lifespan based on emitter velocity |
| Color over Lifetime / by Speed |
Color changes based on age or velocity |
| Size over Lifetime / by Speed |
Dimension changes based on time or speed |
| Rotation over Lifetime / by Speed |
Orientation changes |
| Collision |
Particle collisions with scene geometry |
| Triggers |
Designate particles as collision triggers |
| Sub Emitters |
Particles that emit other particles |
| Texture Sheet Animation |
Texture grid animation frames |
| Trails |
Motion trail rendering |
| Lights |
Real-time lights on particles |
| External Forces |
Wind zones and force fields |
| Renderer |
Image/mesh transform, shading, overdraw |
| Custom Data |
Attach custom data to particles |
VFX Graph Basics
Systems
- Spawn System: Single Spawn Context managing emission
- Particle System: Initialize -> Update -> Output succession
- Mesh Output System: Single Mesh Output Context
Contexts
- Spawn: Executes each frame to calculate spawn amounts. States: Running, Idle, Waiting. Configurable loop duration, count, and delays
- Initialize: Runs at particle birth, sets initial state. Processes Blocks for newly spawned particles. Configurable bounds and capacity
- Update: Per-frame for all living particles. Automatic: position integration, rotation integration, aging, reaping
- Output: Renders particles (Quad, Mesh, etc.). No output ports. Customizable rendering blocks
Graph Elements
- Blocks: Stackable nodes within Contexts; each handles one operation; top-to-bottom execution
- Operators: Low-level property workflow nodes connecting to Block/Context ports
- Properties: Connectable via property workflow
- Settings: Non-connectable editable values per Context
GPU Events
Experimental feature where GPU computes events (vs CPU for normal events). Cannot be customized with Blocks.
Common Patterns (C#)
Create and Configure a Light
using UnityEngine;
public class LightSetup : MonoBehaviour
{
void Start()
{
GameObject lightObj = new GameObject("Dynamic Light");
Light light = lightObj.AddComponent<Light>();
light.type = LightType.Point;
light.color = Color.yellow;
light.intensity = 2.0f;
light.range = 15f;
light.shadows = LightShadows.Soft;
light.shadowResolution = UnityEngine.Rendering.LightShadowResolution.Medium;
}
}
Create a Realtime Reflection Probe
using UnityEngine;
using UnityEngine.Rendering;
public class ProbeSetup : MonoBehaviour
{
void Start()
{
GameObject probeObj = new GameObject("Realtime Reflection Probe");
ReflectionProbe probe = probeObj.AddComponent<ReflectionProbe>();
probe.size = new Vector3(10, 10, 10);
probe.mode = ReflectionProbeMode.Realtime;
probe.refreshMode = ReflectionProbeRefreshMode.EveryFrame;
probe.resolution = 256;
probe.hdr = true;
}
}
Control Particle System at Runtime
using UnityEngine;
public class ParticleController : MonoBehaviour
{
ParticleSystem ps;
void Start()
{
ps = GetComponent<ParticleSystem>();
// Modify emission rate -- cache module in local variable first
var emission = ps.emission;
emission.rateOverTimeMultiplier = 50f;
// Modify main module
var main = ps.main;
main.startLifetime = 3f;
main.startSpeed = 5f;
main.simulationSpace = ParticleSystemSimulationSpace.World;
}
void OnTriggerEnter(Collider other)
{
// Burst emit particles
ps.Emit(100);
}
void OnDisable()
{
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
}
}
VFX Graph Runtime Control
using UnityEngine;
using UnityEngine.VFX;
public class VFXController : MonoBehaviour
{
VisualEffect vfx;
VFXEventAttribute eventAttr;
void Start()
{
vfx = GetComponent<VisualEffect>();
eventAttr = vfx.CreateVFXEventAttribute();
// Set exposed properties
vfx.SetFloat("SpawnRate", 100f);
vfx.SetVector3("Direction", Vector3.up);
vfx.playRate = 1.5f;
}
void OnTriggerEnter(Collider other)
{
// Send custom event with attributes
eventAttr.SetVector3("position", other.transform.position);
vfx.SendEvent("OnHit", eventAttr);
}
public void StopEffect()
{
vfx.Stop();
}
}
Refresh Reflection Probe on Demand
using UnityEngine;
public class ProbeRefresher : MonoBehaviour
{
ReflectionProbe probe;
void Start()
{
probe = GetComponent<ReflectionProbe>();
probe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.ViaScripting;
}
public void RefreshReflections()
{
probe.RenderProbe();
}
public bool IsReady()
{
return probe.IsFinishedRendering(probe.RenderProbe());
}
}
Anti-Patterns
Lighting Anti-Patterns
- Too many Realtime lights: Each realtime light adds per-frame cost. Use Baked or Mixed for static lights
- Forgetting to enable Baked Global Illumination: Mixed/Baked lights silently fall back to Realtime without it
- Overlapping Reflection Probes without Importance values: Causes flickering; always set Importance to establish priority
- Using Area Lights expecting runtime behavior: Area lights are bake-only; they produce no light at runtime
- Ignoring Indirect Multiplier: Leaving at default can cause over-bright or too-dark bounced light; tune per light
- Not setting Shadow Bias correctly: Too low causes self-shadowing artifacts (shadow acne); too high causes peter-panning (shadows detach from objects)
- Manual Light Probe placement in large scenes: Use Adaptive Probe Volumes (APV) in URP instead for automated, per-pixel quality
Particle System Anti-Patterns
- Not caching module references: Each property access on a module struct immediately writes to native code; cache the module variable
- Using World simulation space for attached effects: Particles drift away from moving parents; use Local space for attached FX
- Excessive particle counts on CPU: Particle System is CPU-bound; for >10K particles, consider VFX Graph
- Forgetting to Stop/Clear: Leaked particle systems consume CPU even when invisible
VFX Graph Anti-Patterns
- Using VFX Graph for simple effects on mobile: GPU overhead and URP/HDRP requirement make it overkill for simple mobile effects
- Not setting Capacity in Initialize: Default capacity may allocate too much or too little GPU memory
- Ignoring Bounds: Incorrect bounds cause effects to be culled when visible; always configure bounds in Initialize context
- Sending events every frame without throttling: SendEvent has CPU-GPU sync cost; batch or throttle event dispatch
Key API Quick Reference
Light (UnityEngine.Light)
| Member |
Type |
Description |
type |
Property |
LightType (Directional, Point, Spot, Area) |
color |
Property |
Emitted light color |
intensity |
Property |
Brightness multiplier |
range |
Property |
Max distance (Point/Spot) |
spotAngle / innerSpotAngle |
Property |
Outer/inner cone angles |
shadows |
Property |
LightShadows (None, Hard, Soft) |
shadowResolution |
Property |
Shadow map quality |
shadowBias / shadowNormalBias |
Property |
Shadow artifact reduction |
bounceIntensity |
Property |
GI bounce strength |
cookie |
Property |
Projected texture mask |
cullingMask |
Property |
Layer-based filtering |
colorTemperature |
Property |
CCT in Kelvin |
lightmapBakeType |
Property |
Baking configuration |
bakingOutput |
Property |
Last bake contribution details |
AddCommandBuffer() |
Method |
Execute GPU commands at specified points |
ParticleSystem (UnityEngine.ParticleSystem)
| Member |
Type |
Description |
main / emission / shape |
Property |
Module access structs |
particleCount |
Property |
Current active particles |
isPlaying / isPaused / isStopped |
Property |
Playback state |
Play() / Pause() / Stop() |
Method |
Playback control |
Emit(count) |
Method |
Immediate particle spawn |
Simulate(time) |
Method |
Fast-forward simulation |
GetParticles() / SetParticles() |
Method |
Direct particle data access |
Clear() |
Method |
Remove all particles |
TriggerSubEmitter() |
Method |
Activate sub-emitters |
VisualEffect (UnityEngine.VFX.VisualEffect)
| Member |
Type |
Description |
visualEffectAsset |
Property |
Assign/change effect graph |
playRate |
Property |
Simulation speed |
aliveParticleCount |
Property |
Active particle count |
Play() / Stop() / Reinit() |
Method |
Playback control |
SendEvent(name, attr) |
Method |
Trigger graph events |
CreateVFXEventAttribute() |
Method |
Create event payload |
SetFloat() / SetVector3() / etc. |
Method |
Set exposed properties |
GetFloat() / GetVector3() / etc. |
Method |
Read exposed properties |
HasFloat() / HasVector3() / etc. |
Method |
Check property existence |
ResetOverride(property) |
Method |
Restore original values |
ReflectionProbe (UnityEngine.ReflectionProbe)
| Member |
Type |
Description |
mode |
Property |
Baked/Custom/Realtime |
size / center |
Property |
Bounding box config |
intensity / importance |
Property |
Brightness and priority |
boxProjection |
Property |
Enable box projection |
refreshMode / timeSlicingMode |
Property |
Realtime update config |
RenderProbe() |
Method |
Force cubemap refresh |
IsFinishedRendering() |
Method |
Check time-sliced completion |
BlendCubemap() |
Method |
Blend two cubemaps |
Related Skills
unity-graphics -- Render pipelines (URP/HDRP/Built-in), shaders, materials, cameras
unity-2d -- 2D lighting (URP 2D Renderer), sprite rendering
unity-platforms -- Platform-specific lighting quality tiers, mobile optimization
Additional Resources
1---2name: unity-lighting-vfx3description: Unity 6 lighting and visual effects guide. Use when working with lights, baked/realtime/mixed lighting, light probes, reflection probes, Adaptive Probe Volumes (APV), global illumination, Particle System, VFX Graph, or post-processing effects. Based on Unity 6.3 LTS documentation.4---56# Unity Lighting and Visual Effects78## Lighting Modes910Unity provides three light modes controlling how illumination is calculated.1112### Realtime Lights13- Calculate lighting **every frame at runtime**14- Allow dynamic changes to intensity, color, position15- Cast shadows up to Shadow Distance16- Contribute only direct lighting by default (no bounced light)17- Higher runtime cost, especially in complex scenes or low-end hardware18- Best for: dynamic objects, flickering effects, moving light sources1920### Baked Lights21- Calculations performed **in the Unity Editor** and saved as lighting data to disk22- At runtime, Unity loads pre-computed data instead of calculating dynamically23- Bake both direct and indirect lighting into lightmaps24- Store information in Light Probes for moving objects25- Cannot modify light properties at runtime; do not illuminate dynamic GameObjects26- No specular contributions27- Best for: static scenery, complex indirect lighting, performance-critical scenarios2829### Mixed Lights30- Combine **baked indirect lighting** with **real-time direct lighting**31- Behavior depends on the Lighting Mode setting in the Lighting window32- Cast real-time shadows (not baked soft shadows)33- Can change properties at runtime (affects real-time component only)34- Always more expensive than fully baked lighting35- Best for: dynamic shadows with baked background lighting3637**Important:** All baked/mixed modes require **Baked Global Illumination** enabled. Without it, Mixed and Baked lights behave as Realtime.3839## Light Types4041### Directional Light42- Located infinitely far away, emits light in one direction43- Parallel rays, no distance-based intensity falloff44- Simulates sun/moon; every new scene includes one by default45- Links to procedural sky system; rotate to create time-of-day effects4647### Point Light48- Located at a point, emits in all directions equally49- Intensity follows inverse square law (diminishes with distance squared)50- Use for lamps, explosions, local illumination5152### Spot Light53- Located at a point, emits in a cone shape54- Adjustable cone angle; light diminishes at edges (penumbra)55- Wider angles create larger fade areas56- Use for flashlights, headlights, searchlights5758### Area Light59- Defined by a rectangle or disc; emits uniformly across surface60- Follows inverse square law; produces soft, subtle shading61- **Bake-only** -- not available at runtime62- Use for street lights, realistic interior lighting6364## Global Illumination6566Global illumination (GI) simulates how light bounces between surfaces, producing realistic indirect lighting.6768### Baked GI69- Pre-computes indirect lighting into lightmaps using the **Progressive Lightmapper** (CPU or GPU)70- Results stored in lightmap textures and Light Probes71- Configure in the Lighting window under **Bake** settings72- GPU Progressive Lightmapper offers faster bake times with configurable tile sizes7374### Environment Lighting75Three ambient light sources configured in the Lighting window Environment tab:76- **Skybox**: Uses skybox material colors for ambient light from different angles77- **Gradient**: Separate sky, horizon, and ground colors with smooth blending78- **Color**: Uniform ambient light across the scene7980Intensity Multiplier (0-8, default 1) controls ambient brightness.8182### Environment Reflections83- Source: Skybox or custom Cubemap/RenderTexture84- Configurable resolution, compression, intensity multiplier85- Bounces setting controls reflection evaluation iterations between objects8687## Light Probes and Adaptive Probe Volumes8889### Light Probes90- Capture lighting information in **empty space** throughout a scene91- At runtime, indirect lighting for dynamic GameObjects is approximated using nearest probes92- Provide indirect bounced light for moving objects and LOD system support93- Must be manually placed using Light Probe Groups94- Store baked lighting information; work with both direct and indirect lighting9596### Adaptive Probe Volumes (APV)97APV is the modern replacement for manual Light Probe placement in URP:98- **Automated probe placement** -- eliminates manual Light Probe Group positioning99- **Per-pixel lighting** -- superior quality compared to per-object approaches100- **Scene baking** -- bake multiple scenes together using Baking Sets101- **Runtime adjustments** -- Lighting Scenarios and sky occlusion for dynamic changes102- **Large-world support** -- streaming data for expansive open-world environments103- **Data flexibility** -- loading from AssetBundles or Addressables104- Configurable probe density and volume size with visualization tools105106## Reflection Probes107108Capture a spherical view of surroundings as a cubemap for reflective materials.109110### Types111| Type | Description |112|------|-------------|113| **Baked** | Captures static GameObjects only; best performance |114| **Custom** | Allows dynamic object capture with custom textures |115| **Realtime** | Updates during gameplay; configurable refresh mode |116117### Key Properties118- **Importance**: Rendering priority when multiple probes overlap119- **Intensity**: Texture brightness in shader calculations120- **Box Projection**: Enables projection mapping for interiors (requires URP config)121- **Box Size/Offset**: World-space bounding box for reflection contribution122- **Blend Distance**: Blending distance for deferred probes123124### Realtime Options125- **Refresh Mode**: On Awake, Every Frame, or Via Scripting126- **Time Slicing**: All Faces At Once, Individual Faces, No Time Slicing127128## Particle System vs VFX Graph129130| Feature | Particle System | VFX Graph |131|---------|----------------|-----------|132| Simulation | CPU-based | GPU-based |133| Particle count | Thousands | Millions |134| Render pipeline | All pipelines | URP/HDRP only |135| Authoring | Inspector modules | Node-based graph editor |136| Physics | Built-in collision | Custom collision blocks |137| Scripting | Full C# API | Event-based C# API |138| Sub-emitters | Native support | GPU Event contexts |139| Best for | Small/medium effects, mobile | Large-scale effects, high-end |140141**Decision Guide:**142- Use **Particle System** for mobile targets, simple effects, when you need full CPU-side scripting control, or when targeting the Built-in Render Pipeline143- Use **VFX Graph** for massive particle counts, GPU-driven simulations, complex node-based authoring, or high-end platforms with URP/HDRP144145## Particle System Modules146147| Module | Purpose |148|--------|---------|149| **Main** | Initial state: lifetime, speed, size, gravity, simulation space |150| **Emission** | Rate and timing of particle spawns |151| **Shape** | Volume/surface for emission and start velocity direction |152| **Velocity over Lifetime** | Modify movement over particle age |153| **Noise** | Turbulence for organic, chaotic motion |154| **Limit Velocity over Lifetime** | Natural deceleration |155| **Force over Lifetime** | Simulated physics forces |156| **Inherit Velocity** | Sub-emitter particles match parent velocity |157| **Lifetime by Emitter Speed** | Adjust lifespan based on emitter velocity |158| **Color over Lifetime / by Speed** | Color changes based on age or velocity |159| **Size over Lifetime / by Speed** | Dimension changes based on time or speed |160| **Rotation over Lifetime / by Speed** | Orientation changes |161| **Collision** | Particle collisions with scene geometry |162| **Triggers** | Designate particles as collision triggers |163| **Sub Emitters** | Particles that emit other particles |164| **Texture Sheet Animation** | Texture grid animation frames |165| **Trails** | Motion trail rendering |166| **Lights** | Real-time lights on particles |167| **External Forces** | Wind zones and force fields |168| **Renderer** | Image/mesh transform, shading, overdraw |169| **Custom Data** | Attach custom data to particles |170171## VFX Graph Basics172173### Systems1741. **Spawn System**: Single Spawn Context managing emission1752. **Particle System**: Initialize -> Update -> Output succession1763. **Mesh Output System**: Single Mesh Output Context177178### Contexts179- **Spawn**: Executes each frame to calculate spawn amounts. States: Running, Idle, Waiting. Configurable loop duration, count, and delays180- **Initialize**: Runs at particle birth, sets initial state. Processes Blocks for newly spawned particles. Configurable bounds and capacity181- **Update**: Per-frame for all living particles. Automatic: position integration, rotation integration, aging, reaping182- **Output**: Renders particles (Quad, Mesh, etc.). No output ports. Customizable rendering blocks183184### Graph Elements185- **Blocks**: Stackable nodes within Contexts; each handles one operation; top-to-bottom execution186- **Operators**: Low-level property workflow nodes connecting to Block/Context ports187- **Properties**: Connectable via property workflow188- **Settings**: Non-connectable editable values per Context189190### GPU Events191Experimental feature where GPU computes events (vs CPU for normal events). Cannot be customized with Blocks.192193## Common Patterns (C#)194195### Create and Configure a Light196```csharp197using UnityEngine;198199public class LightSetup : MonoBehaviour200{201 void Start()202 {203 GameObject lightObj = new GameObject("Dynamic Light");204 Light light = lightObj.AddComponent<Light>();205 light.type = LightType.Point;206 light.color = Color.yellow;207 light.intensity = 2.0f;208 light.range = 15f;209 light.shadows = LightShadows.Soft;210 light.shadowResolution = UnityEngine.Rendering.LightShadowResolution.Medium;211 }212}213```214215### Create a Realtime Reflection Probe216```csharp217using UnityEngine;218using UnityEngine.Rendering;219220public class ProbeSetup : MonoBehaviour221{222 void Start()223 {224 GameObject probeObj = new GameObject("Realtime Reflection Probe");225 ReflectionProbe probe = probeObj.AddComponent<ReflectionProbe>();226 probe.size = new Vector3(10, 10, 10);227 probe.mode = ReflectionProbeMode.Realtime;228 probe.refreshMode = ReflectionProbeRefreshMode.EveryFrame;229 probe.resolution = 256;230 probe.hdr = true;231 }232}233```234235### Control Particle System at Runtime236```csharp237using UnityEngine;238239public class ParticleController : MonoBehaviour240{241 ParticleSystem ps;242243 void Start()244 {245 ps = GetComponent<ParticleSystem>();246247 // Modify emission rate -- cache module in local variable first248 var emission = ps.emission;249 emission.rateOverTimeMultiplier = 50f;250251 // Modify main module252 var main = ps.main;253 main.startLifetime = 3f;254 main.startSpeed = 5f;255 main.simulationSpace = ParticleSystemSimulationSpace.World;256 }257258 void OnTriggerEnter(Collider other)259 {260 // Burst emit particles261 ps.Emit(100);262 }263264 void OnDisable()265 {266 ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);267 }268}269```270271### VFX Graph Runtime Control272```csharp273using UnityEngine;274using UnityEngine.VFX;275276public class VFXController : MonoBehaviour277{278 VisualEffect vfx;279 VFXEventAttribute eventAttr;280281 void Start()282 {283 vfx = GetComponent<VisualEffect>();284 eventAttr = vfx.CreateVFXEventAttribute();285286 // Set exposed properties287 vfx.SetFloat("SpawnRate", 100f);288 vfx.SetVector3("Direction", Vector3.up);289 vfx.playRate = 1.5f;290 }291292 void OnTriggerEnter(Collider other)293 {294 // Send custom event with attributes295 eventAttr.SetVector3("position", other.transform.position);296 vfx.SendEvent("OnHit", eventAttr);297 }298299 public void StopEffect()300 {301 vfx.Stop();302 }303}304```305306### Refresh Reflection Probe on Demand307```csharp308using UnityEngine;309310public class ProbeRefresher : MonoBehaviour311{312 ReflectionProbe probe;313314 void Start()315 {316 probe = GetComponent<ReflectionProbe>();317 probe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.ViaScripting;318 }319320 public void RefreshReflections()321 {322 probe.RenderProbe();323 }324325 public bool IsReady()326 {327 return probe.IsFinishedRendering(probe.RenderProbe());328 }329}330```331332## Anti-Patterns333334### Lighting Anti-Patterns3351. **Too many Realtime lights**: Each realtime light adds per-frame cost. Use Baked or Mixed for static lights3362. **Forgetting to enable Baked Global Illumination**: Mixed/Baked lights silently fall back to Realtime without it3373. **Overlapping Reflection Probes without Importance values**: Causes flickering; always set Importance to establish priority3384. **Using Area Lights expecting runtime behavior**: Area lights are bake-only; they produce no light at runtime3395. **Ignoring Indirect Multiplier**: Leaving at default can cause over-bright or too-dark bounced light; tune per light3406. **Not setting Shadow Bias correctly**: Too low causes self-shadowing artifacts (shadow acne); too high causes peter-panning (shadows detach from objects)3417. **Manual Light Probe placement in large scenes**: Use Adaptive Probe Volumes (APV) in URP instead for automated, per-pixel quality342343### Particle System Anti-Patterns3441. **Not caching module references**: Each property access on a module struct immediately writes to native code; cache the module variable3452. **Using World simulation space for attached effects**: Particles drift away from moving parents; use Local space for attached FX3463. **Excessive particle counts on CPU**: Particle System is CPU-bound; for >10K particles, consider VFX Graph3474. **Forgetting to Stop/Clear**: Leaked particle systems consume CPU even when invisible348349### VFX Graph Anti-Patterns3501. **Using VFX Graph for simple effects on mobile**: GPU overhead and URP/HDRP requirement make it overkill for simple mobile effects3512. **Not setting Capacity in Initialize**: Default capacity may allocate too much or too little GPU memory3523. **Ignoring Bounds**: Incorrect bounds cause effects to be culled when visible; always configure bounds in Initialize context3534. **Sending events every frame without throttling**: SendEvent has CPU-GPU sync cost; batch or throttle event dispatch354355## Key API Quick Reference356357### Light (UnityEngine.Light)358| Member | Type | Description |359|--------|------|-------------|360| `type` | Property | LightType (Directional, Point, Spot, Area) |361| `color` | Property | Emitted light color |362| `intensity` | Property | Brightness multiplier |363| `range` | Property | Max distance (Point/Spot) |364| `spotAngle` / `innerSpotAngle` | Property | Outer/inner cone angles |365| `shadows` | Property | LightShadows (None, Hard, Soft) |366| `shadowResolution` | Property | Shadow map quality |367| `shadowBias` / `shadowNormalBias` | Property | Shadow artifact reduction |368| `bounceIntensity` | Property | GI bounce strength |369| `cookie` | Property | Projected texture mask |370| `cullingMask` | Property | Layer-based filtering |371| `colorTemperature` | Property | CCT in Kelvin |372| `lightmapBakeType` | Property | Baking configuration |373| `bakingOutput` | Property | Last bake contribution details |374| `AddCommandBuffer()` | Method | Execute GPU commands at specified points |375376### ParticleSystem (UnityEngine.ParticleSystem)377| Member | Type | Description |378|--------|------|-------------|379| `main` / `emission` / `shape` | Property | Module access structs |380| `particleCount` | Property | Current active particles |381| `isPlaying` / `isPaused` / `isStopped` | Property | Playback state |382| `Play()` / `Pause()` / `Stop()` | Method | Playback control |383| `Emit(count)` | Method | Immediate particle spawn |384| `Simulate(time)` | Method | Fast-forward simulation |385| `GetParticles()` / `SetParticles()` | Method | Direct particle data access |386| `Clear()` | Method | Remove all particles |387| `TriggerSubEmitter()` | Method | Activate sub-emitters |388389### VisualEffect (UnityEngine.VFX.VisualEffect)390| Member | Type | Description |391|--------|------|-------------|392| `visualEffectAsset` | Property | Assign/change effect graph |393| `playRate` | Property | Simulation speed |394| `aliveParticleCount` | Property | Active particle count |395| `Play()` / `Stop()` / `Reinit()` | Method | Playback control |396| `SendEvent(name, attr)` | Method | Trigger graph events |397| `CreateVFXEventAttribute()` | Method | Create event payload |398| `SetFloat()` / `SetVector3()` / etc. | Method | Set exposed properties |399| `GetFloat()` / `GetVector3()` / etc. | Method | Read exposed properties |400| `HasFloat()` / `HasVector3()` / etc. | Method | Check property existence |401| `ResetOverride(property)` | Method | Restore original values |402403### ReflectionProbe (UnityEngine.ReflectionProbe)404| Member | Type | Description |405|--------|------|-------------|406| `mode` | Property | Baked/Custom/Realtime |407| `size` / `center` | Property | Bounding box config |408| `intensity` / `importance` | Property | Brightness and priority |409| `boxProjection` | Property | Enable box projection |410| `refreshMode` / `timeSlicingMode` | Property | Realtime update config |411| `RenderProbe()` | Method | Force cubemap refresh |412| `IsFinishedRendering()` | Method | Check time-sliced completion |413| `BlendCubemap()` | Method | Blend two cubemaps |414415## Related Skills416- `unity-graphics` -- Render pipelines (URP/HDRP/Built-in), shaders, materials, cameras417- `unity-2d` -- 2D lighting (URP 2D Renderer), sprite rendering418- `unity-platforms` -- Platform-specific lighting quality tiers, mobile optimization419420## Additional Resources421- [Lighting Overview](https://docs.unity3d.com/6000.3/Documentation/Manual/LightingOverview.html)422- [Light Types](https://docs.unity3d.com/6000.3/Documentation/Manual/LightTypes.html)423- [Light Modes](https://docs.unity3d.com/6000.3/Documentation/Manual/LightModes-introduction.html)424- [Light Probes](https://docs.unity3d.com/6000.3/Documentation/Manual/LightProbes.html)425- [Reflection Probes](https://docs.unity3d.com/6000.3/Documentation/Manual/ReflectionProbes.html)426- [Adaptive Probe Volumes (URP)](https://docs.unity3d.com/6000.3/Documentation/Manual/urp/probevolumes.html)427- [Particle System Modules](https://docs.unity3d.com/6000.3/Documentation/Manual/configuring-particles.html)428- [VFX Graph Package](https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@17.0/manual/index.html)429- [Light Scripting API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Light.html)430- [ParticleSystem Scripting API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/ParticleSystem.html)431- [ReflectionProbe Scripting API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/ReflectionProbe.html)