> Learn about sub emitters in Babylon.js.

Source: https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/subEmitters

# Sub Emitters

Starting from Babylon.js v3.2, you can create sub emitters, which let you spawn a new particle from an existing particle. Each spawned sub-particle system is totally independent of the parent.

**Note:** Sub emitters are not supported in GPU particles.

## How To Use Sub Emitters

The list of sub-particle systems used as sub emitters is kept in an array and assigned to the `subEmitters` property of the appropriate system.

```javascript
// Create sub emitter
var subEmitter = new BABYLON.SubEmitter(subParticleSystem);
// Have the sub emitter spawn the particle system when the particle dies
subEmitter.type = BABYLON.SubEmitterType.END;
// Set the +Y direction of the sub emitter equal to the direction the particle is/was heading
subEmitter.inheritDirection = true;
// How much of the existing particles speed should be added to the emitter particles
subEmitter.inheritedVelocityAmount = 1;

particleSystem.subEmitters = [subEmitter];
```

If you specify an array of arrays of sub emitters, a random array will be chosen, and all the sub emitters in that array will be attached to the spawned particle.

```javascript
particleSystem.subEmitters = [[subEmitter],[subEmitter, subEmitter2, subEmitter3], [subEmitter4]];
```

## END Sub Emitter Type

When a particle dies, one of the particle systems in the array is selected at random as the one to be spawned. It is then cloned and rendered. Any element of the array can itself have `subEmitters`, and hence a chain of sub emitters can be formed. In this case, the property `manualEmitCount` could be used to avoid an infinite loop of creating and spawning new systems.

## ATTACHED Sub Emitter Type

When a particle is spawned, this emitter will be cloned and attached to the new particle. This can be used to create a trailing particle effect on new particles.

To make attached sub emitters respect orientation when emitting particles, their emitter must be a mesh type:

```javascript
subEmitter.particleSystem.emitter = new BABYLON.Mesh("", scene);
```

## Active Sub Systems

Each particle system that has sub emitters also has a property `activeSubSystems`, which is an array containing all currently active sub particle systems.

You can stop the root `ParticleSystem` and all `activeSubSystems` by calling the `stop` function on the root system:

```javascript
particleSystem.stop(); 
```

When you want to stop the root system without affecting the `activeSubSystems`, you pass `false` to the `stop` function:

```javascript
particleSystem.stop(false);
```

## Demos

- [Playground: Sub Emitters](https://playground.babylonjs.com/#T0L01N#47) - Simple example of sub emitters.
- [Playground: Sub Emitters On Death Only](https://playground.babylonjs.com/#9NHBCC#1) - Simple example of sub emitters on death only.
- [Playground: Complete Example (Hit Space To Launch a Barrel)](https://playground.babylonjs.com/#7HH1UH#6) - Complete sub emitter example.

## Further reading

- [Particles Overview](https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system)
- [Particles 101](https://doc.babylonjs.com/features/featuresDeepDive/particles)
- [How to Create Animated Particles](https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/animation)
- [Solid Particle System](https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system)
- [How to Customize the Particle System](https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/customizingParticles)
