Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ParticleSystem.SubEmittersModule.AddSubEmitter

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public method AddSubEmitter(subEmitter: ParticleSystem, type: ParticleSystemSubEmitterType, properties: ParticleSystemSubEmitterProperties): void;
public void AddSubEmitter(ParticleSystem subEmitter, ParticleSystemSubEmitterType type, ParticleSystemSubEmitterProperties properties);

Parameters

subEmitterThe sub-emitter to be added.
typeThe event that creates new particles.
propertiesThe properties of the new particles.

Description

Add a new sub-emitter.

#pragma strict
// Add a birth sub-emitter
function Start() {
	// A simple particle material with no texture.
	var particleMaterial: Material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
	// Create a green particle system.
	var rootSystemGO: var = new GameObject("Particle System");
	rootSystemGO.transform.Rotate(-90, 0, 0);
	// Rotate so the system emits upwards.
	var rootParticleSystem: var = rootSystemGO.AddComponent.<ParticleSystem>();
	rootSystemGO.GetComponent.<ParticleSystemRenderer>().material = particleMaterial;
	var mainModule: var = rootParticleSystem.main;
	mainModule.startColor = Color.green;
	mainModule.startSize = 0.5f;
	// Spread the particles out more so the sub-emitter effect is more obvious.
	var shapeModule: var = rootParticleSystem.shape;
	shapeModule.radius = 100;
	// Create our sub-emitter and set up bursts.
	var subSystemGO: var = new GameObject("Particle System");
	var subParticleSystem: var = subSystemGO.AddComponent.<ParticleSystem>();
	subSystemGO.GetComponent.<ParticleSystemRenderer>().material = particleMaterial;
	var subMainModule: var = subParticleSystem.main;
	subMainModule.startColor = Color.red;
	subMainModule.startSize = 0.25f;
	subMainModule.startLifetime = 0.5f;
	// very short life particles.
	var emissionModule: var = subParticleSystem.emission;
	emissionModule.rate = 2;
	// 1 particle will emit every 0.5 sec.
	emissionModule.SetBursts([new ParticleSystem.Burst(1.0f, 10), new ParticleSystem.Burst(3.0f, 10)]);
	// Set up the sub particles so they fade over time.
	var colorModule: var = subParticleSystem.colorOverLifetime;
	colorModule.enabled = true;
	var gradient: var = new Gradient();
	gradient.SetKeys([new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f)], [new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f)]);
	// Alpha fades
	colorModule.color = gradient;
	// Setup the sub-emitter.
	subSystemGO.transform.SetParent(rootSystemGO.transform);
	var subEmittersModule: var = rootParticleSystem.subEmitters;
	subEmittersModule.enabled = true;
	subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Birth, ParticleSystemSubEmitterProperties.InheritNothing);
}
using UnityEngine;

// Add a birth sub-emitter public class ExampleClass : MonoBehaviour { void Start() { // A simple particle material with no texture. Material particleMaterial = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));

// Create a green particle system. var rootSystemGO = new GameObject("Particle System"); rootSystemGO.transform.Rotate(-90, 0, 0); // Rotate so the system emits upwards. var rootParticleSystem = rootSystemGO.AddComponent<ParticleSystem>(); rootSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var mainModule = rootParticleSystem.main; mainModule.startColor = Color.green; mainModule.startSize = 0.5f;

// Spread the particles out more so the sub-emitter effect is more obvious. var shapeModule = rootParticleSystem.shape; shapeModule.radius = 100;

// Create our sub-emitter and set up bursts. var subSystemGO = new GameObject("Particle System"); var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>(); subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var subMainModule = subParticleSystem.main; subMainModule.startColor = Color.red; subMainModule.startSize = 0.25f; subMainModule.startLifetime = 0.5f; // very short life particles. var emissionModule = subParticleSystem.emission; emissionModule.rate = 2; // 1 particle will emit every 0.5 sec. emissionModule.SetBursts(new ParticleSystem.Burst[] // A burst will emit at 1 and 3 secs. { new ParticleSystem.Burst(1.0f, 10), new ParticleSystem.Burst(3.0f, 10) });

// Set up the sub particles so they fade over time. var colorModule = subParticleSystem.colorOverLifetime; colorModule.enabled = true; var gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f) }, // Color remains untouched. new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }); // Alpha fades colorModule.color = gradient;

// Setup the sub-emitter. subSystemGO.transform.SetParent(rootSystemGO.transform); var subEmittersModule = rootParticleSystem.subEmitters; subEmittersModule.enabled = true; subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Birth, ParticleSystemSubEmitterProperties.InheritNothing); } }
#pragma strict
// Add a collision sub-emitter
function Start() {
	// For this example we will need something to collide with in the world.
	var cube: var = GameObject.CreatePrimitive(PrimitiveType.Cube);
	cube.transform.position = new Vector3(0, 10, 0);
	// Position above the particle system.
	cube.transform.localScale = new Vector3(10, 10, 10);
	// A simple particle material with no texture.
	var particleMaterial: Material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
	// Create a green particle system.
	var rootSystemGO: var = new GameObject("Particle System");
	rootSystemGO.transform.Rotate(-90, 0, 0);
	// Rotate so the system emits upwards.
	var rootParticleSystem: var = rootSystemGO.AddComponent.<ParticleSystem>();
	rootSystemGO.GetComponent.<ParticleSystemRenderer>().material = particleMaterial;
	var mainModule: var = rootParticleSystem.main;
	mainModule.startColor = Color.green;
	mainModule.startSize = 0.5f;
	// Enable and setup the collisions module.
	var collisionModule: var = rootParticleSystem.collision;
	collisionModule.enabled = true;
	collisionModule.type = ParticleSystemCollisionType.World;
	// Create our sub-emitter and setup bursts.
	var subSystemGO: var = new GameObject("Particle System");
	var subParticleSystem: var = subSystemGO.AddComponent.<ParticleSystem>();
	subSystemGO.GetComponent.<ParticleSystemRenderer>().material = particleMaterial;
	var subMainModule: var = subParticleSystem.main;
	subMainModule.startColor = Color.red;
	subMainModule.startSize = 0.25f;
	var emissionModule: var = subParticleSystem.emission;
	emissionModule.SetBursts([new ParticleSystem.Burst(0.0f, 10)]);
	// Set up the sub-emitter.
	subSystemGO.transform.SetParent(rootSystemGO.transform);
	var subEmittersModule: var = rootParticleSystem.subEmitters;
	subEmittersModule.enabled = true;
	subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Collision, ParticleSystemSubEmitterProperties.InheritNothing);
}
using UnityEngine;

// Add a collision sub-emitter public class ExampleClass : MonoBehaviour { void Start() { // For this example we will need something to collide with in the world. var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(0, 10, 0); // Position above the particle system. cube.transform.localScale = new Vector3(10, 10, 10);

// A simple particle material with no texture. Material particleMaterial = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));

// Create a green particle system. var rootSystemGO = new GameObject("Particle System"); rootSystemGO.transform.Rotate(-90, 0, 0); // Rotate so the system emits upwards. var rootParticleSystem = rootSystemGO.AddComponent<ParticleSystem>(); rootSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var mainModule = rootParticleSystem.main; mainModule.startColor = Color.green; mainModule.startSize = 0.5f;

// Enable and setup the collisions module. var collisionModule = rootParticleSystem.collision; collisionModule.enabled = true; collisionModule.type = ParticleSystemCollisionType.World;

// Create our sub-emitter and setup bursts. var subSystemGO = new GameObject("Particle System"); var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>(); subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var subMainModule = subParticleSystem.main; subMainModule.startColor = Color.red; subMainModule.startSize = 0.25f; var emissionModule = subParticleSystem.emission; emissionModule.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, 10) }); // We will emit 10 particles upon collision.

// Set up the sub-emitter. subSystemGO.transform.SetParent(rootSystemGO.transform); var subEmittersModule = rootParticleSystem.subEmitters; subEmittersModule.enabled = true; subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Collision, ParticleSystemSubEmitterProperties.InheritNothing); } }
#pragma strict
// Add a death sub-emitter
function Start() {
	// A simple particle material with no texture.
	var particleMaterial: Material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
	// Create a green particle system.
	var rootSystemGO: var = new GameObject("Particle System");
	rootSystemGO.transform.Rotate(-90, 0, 0);
	// Rotate so the system emits upwards.
	var rootParticleSystem: var = rootSystemGO.AddComponent.<ParticleSystem>();
	rootSystemGO.GetComponent.<ParticleSystemRenderer>().material = particleMaterial;
	var mainModule: var = rootParticleSystem.main;
	mainModule.startColor = Color.green;
	mainModule.startSize = 0.5f;
	// Create our sub-emitter and setup bursts.
	var subSystemGO: var = new GameObject("Particle System");
	var subParticleSystem: var = subSystemGO.AddComponent.<ParticleSystem>();
	subSystemGO.GetComponent.<ParticleSystemRenderer>().material = particleMaterial;
	var subMainModule: var = subParticleSystem.main;
	subMainModule.startColor = Color.red;
	subMainModule.startSize = 0.25f;
	var emissionModule: var = subParticleSystem.emission;
	emissionModule.SetBursts([new ParticleSystem.Burst(0.0f, 10)]);
	// Set up the sub-emitter.
	subSystemGO.transform.SetParent(rootSystemGO.transform);
	var subEmittersModule: var = rootParticleSystem.subEmitters;
	subEmittersModule.enabled = true;
	subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritNothing);
}
using UnityEngine;

// Add a death sub-emitter public class ExampleClass : MonoBehaviour { void Start() { // A simple particle material with no texture. Material particleMaterial = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));

// Create a green particle system. var rootSystemGO = new GameObject("Particle System"); rootSystemGO.transform.Rotate(-90, 0, 0); // Rotate so the system emits upwards. var rootParticleSystem = rootSystemGO.AddComponent<ParticleSystem>(); rootSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var mainModule = rootParticleSystem.main; mainModule.startColor = Color.green; mainModule.startSize = 0.5f;

// Create our sub-emitter and setup bursts. var subSystemGO = new GameObject("Particle System"); var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>(); subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var subMainModule = subParticleSystem.main; subMainModule.startColor = Color.red; subMainModule.startSize = 0.25f; var emissionModule = subParticleSystem.emission; emissionModule.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, 10) }); // We will emit 10 particles upon death.

// Set up the sub-emitter. subSystemGO.transform.SetParent(rootSystemGO.transform); var subEmittersModule = rootParticleSystem.subEmitters; subEmittersModule.enabled = true; subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritNothing); } }
no example available in JavaScript
using UnityEngine;

// Add a manual sub-emitter public class ExampleClass : MonoBehaviour { private ParticleSystem ps; private float m_Timer = 0.0f; public float m_Interval = 2.0f;

void Start() { // A simple particle material with no texture. Material particleMaterial = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));

// Create a green particle system. var rootSystemGO = new GameObject("Particle System"); rootSystemGO.transform.Rotate(-90, 0, 0); // Rotate so the system emits upwards. ps = rootSystemGO.AddComponent<ParticleSystem>(); rootSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var mainModule = ps.main; mainModule.startColor = Color.green; mainModule.startSize = 0.5f;

// Create our sub-emitter and setup bursts. var subSystemGO = new GameObject("Particle System"); var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>(); subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var subMainModule = subParticleSystem.main; subMainModule.startColor = Color.red; subMainModule.startSize = 0.25f; var emissionModule = subParticleSystem.emission; emissionModule.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, 4) }); // We will emit 10 particles when triggered.

// Set up the sub-emitter. subSystemGO.transform.SetParent(rootSystemGO.transform); var subEmittersModule = ps.subEmitters; subEmittersModule.enabled = true; subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Manual, ParticleSystemSubEmitterProperties.InheritNothing); }

private void Update() { m_Timer += Time.deltaTime; while (m_Timer >= m_Interval) { ps.TriggerSubEmitter(0); m_Timer -= m_Interval; } } }

Did you find this page useful? Please give it a rating: