How to fade out decal particles using color over lifetime?

I’m using a particle system to display decals. Play on awake and loop are disabled so the system never plays. Emission is disabled. Color over lifetime is a gradient going from white with alpha 255 to white with alpha 0.

To write the particles, I set their position, 3drotation, startSize and startColor. They appear as they should, no problem so far.

Now at some point I want to fade out the currently displaying decals. For that I get all the particles, loop through them and set their startLifetime to a few seconds. Then I write them back with SetParticles.

Problem is, they don’t fade out but instead all the particles are killed immediately. I checked by trying to get the system’s particles in the next Update call (which is only ~1 frame later, not anyone near the lifetime I set) but by then the system is already empty.

Just a thought without testing: First you can set startlifetime in the editor to “infinity” if it’s indefinite, also just disable color over lifetime module. In the script where you loop the all got particles, don’t change their lifetime, but do a lerp of the alpha of startColor (Color32), sth like:

m_particles.startColor = new Color32 (m_particles.startColor.r, m_particles.startColor.g, m_particles.startColor.b, Mathf.Lerp(m_particles*.startColor.a, 0f, time.deltaTime/fadeoutDuration);
if(m_particles.startColor.a == 0f){
m_particles.remainingLifetime = 0f;
_}*
Preferably do it in a Coroutine instead of Update._

To sum up the solution I found with the help of ifurkend:

  • Both startLifetime and remainingLifetime need to be set (to the same value).
  • The particle system needs to be set to play so it actually animates. I set it to stop again when I replace the old decals with new ones, because those should stay put.