Sub-emitters let you create extra particle effects that start when main particles die or collide. This helps make effects look more natural and exciting.
0
0
Sub-emitters in Unity
Introduction
When you want sparks to fly out after a firework explodes.
To create smoke puffs after a bullet hits a surface.
For adding small explosions after a big explosion fades.
When particles should trigger other effects on collision.
To chain particle effects for more complex visuals.
Syntax
Unity
ParticleSystem subEmitter = mainParticleSystem.subEmitters.AddSubEmitter(subEmitterPrefab, SubEmitterType.Birth, SubEmitterProperties.InheritColor);
Use
SubEmitterType to decide when the sub-emitter triggers: on Birth, Collision, or Death of the main particle.Sub-emitters are added to the main particle system's
subEmitters property.Examples
Adds a smoke effect that starts when each main particle dies.
Unity
mainParticleSystem.subEmitters.AddSubEmitter(smokePrefab, SubEmitterType.Death, SubEmitterProperties.None);Adds sparks that appear when particles collide, inheriting the main particle's color.
Unity
mainParticleSystem.subEmitters.AddSubEmitter(sparkPrefab, SubEmitterType.Collision, SubEmitterProperties.InheritColor);
Creates a flash effect every time a new particle is born, inheriting its lifetime.
Unity
mainParticleSystem.subEmitters.AddSubEmitter(flashPrefab, SubEmitterType.Birth, SubEmitterProperties.InheritLifetime);
Sample Program
This script adds a sub-emitter to the main particle system. The sub-emitter plays its effect whenever a main particle dies, such as smoke or sparks. It then starts the main particle system.
Unity
using UnityEngine; public class SubEmitterExample : MonoBehaviour { public ParticleSystem mainParticleSystem; public ParticleSystem subEmitterPrefab; void Start() { // Add a sub-emitter that triggers when main particles die mainParticleSystem.subEmitters.AddSubEmitter(subEmitterPrefab, SubEmitterType.Death, SubEmitterProperties.None); // Start the main particle system mainParticleSystem.Play(); } }
OutputSuccess
Important Notes
Sub-emitters only work if the main particle system has subEmitters enabled.
Remember to assign the sub-emitter prefab in the Unity Editor or by script before adding it.
Sub-emitters can affect performance if overused, so use them wisely.
Summary
Sub-emitters create extra particle effects triggered by main particles.
They can start on particle birth, collision, or death.
Use them to make effects more dynamic and realistic.