Multiple particle fade

Hi, I found the script that originally made by Josh and then updated to work on the new API.
It works flawlessly but it only does that to emitter0. emitter1, 2, 3 and 4 didn’t fade out before they die.
I’m super new to scripting. Can anyone help me so it also works to other emitters?

this is the script that i found:

// In this script we show how to fade out particles from
// a emitter. 
// Original post was created by Josh Beckwith
// URL:

// Include modules
const Scene = require('Scene');
const Animation = require('Animation');

// Load 'emitter0' object.
Scene.root.findFirst('emitter0').then(emitter => {
  // emitter0 loaded and ready to be used.
  // Animate per channel in a HSVA color model.
  // We specify a easing functions for the 
  // rate of change of a channel over time.
  // More info per under channel.
  // Read more about HSV color model here:
  // Read more about easing functions here:
  emitter.hsvaColorModulationModifier = Animation.samplers.HSVA([
  	// H for hue.
  	// Here we tell the Hue channel should have a constant
  	// value of 1 during the lifespan of a particle.
  	// So the Hue vil always stay 1 from start to finish.
    // S for saturation.
    // Here we use contsant again.
    // V for value.
    // And the same here.
    // A for alpha.
    // Here we use a easeInQuad easing function to gradually 
    // change the Alpha channel value for the particle over time.
    // The value will transition from 1 (100% visible) to 0 
    // (0% visible) with a non-linear speed.
    // Read more about easeInQuad here:
    Animation.samplers.easeInQuad(1, 0)

  // The same rules can be applied to other particle properties
  // such as size. Here we are trying out the easeInCirc easing
  // function. All available easing functions in Spark AR
  // can be found here: 
  emitter.sizeModifier = Animation.samplers.easeInCirc(0, 0.01);

  // Other particle properties that can be modified include 
  // positionModifier and velocityModifier.
  // More information is specified here:

I think the simplest solution would be to just duplicate the script and change the name in each of them. Otherwise, you will need to write some kind of iterator, or apply the properties manually to each of the emitters. I wrote some very rough code below to illustrate the basic ideas.

Promise.all( Scene.root.findByPattern('emitter*') ).then(arrayOfEmitters => {
    arrayOfEmitters.forEach(emitter => {...})
    arrayOfEmitters[0].sizeModifier = ...

Note: written without consulting docs. Not sure about the pattern thing…

Hi josh, thank you… yeah i figured i just copy paste the whole set of Scene.root.findFirst(‘emitter0’).then(emitter => {
and just change the name. that works. thank you :slight_smile: