- Home /
Particle system won't restart emitting before last particle has died
I'm trying to make a particle system emit whenever I hold a button down and stop emitting when I'm not pressing the button. The particles have a 1 second lifetime and they die on collision.
The problem is that if I let go of the button and press it again quickly, the particle system won't start emitting again before the previous particles have died either by running out of lifetime or by colliding with anything. I only have to wait for the previous particles to die after I have called either Stop() or Emit().
The same problem persisted whether I was using Emit() or Stop() and Play(). I also tried using Clear() before Play() but it didn't help.
Unity version 5.3.5f1
I didn't really find a fix for the problem but I found a workaround that works for my use-case. Ins$$anonymous$$d of stopping and starting the particle system I changed the alpha value of the particle systems startColor between 0 and 255 to make any particles emitted when I'm not holding the button invisible.
Answer by Velorom · Sep 02, 2017 at 01:22 PM
Also you can enable/disable an emission module:
ParticleSystem.EmissionModule em = particleSystem.emission;
em.enabled = false;
This worked nicely. I don't understand why this bug is still in the particle system. Practically you cannot turn the particle system on/off in short periods that are under the length of the particles lifetime. However it's a good workaround I suppose it's not the best to keep a particle system playing (even with emitter off) from optimization aspect.
In 2020 this is still the cleanest answer I've found and did exactly as Play > Stop > Play should do but for some reason still won't.
Answer by seandanger · Feb 12, 2021 at 10:20 PM
Forcing the particles to stop and clear fixed the problem for me. I feel like this should be standard behavior though. I wrote an extension method that I use in place of Play() for my particle systems, maybe someone else will find it useful:
public static class UnityUtils
{
public static void PlayProperly(this ParticleSystem particles, bool withChildren = true)
{
if (particles.isPlaying)
particles.Stop(withChildren, ParticleSystemStopBehavior.StopEmittingAndClear);
particles.Play(withChildren);
}
}
Answer by farid_fahara · Nov 11, 2020 at 02:08 PM
just uncheck loop in the particle system and create a new clone of the particle system when you click the button
Your answer
Follow this Question
Related Questions
Particles and scrolling objects 0 Answers
Can I make uniform emission for Particle System? 2 Answers
Emit particles from image/sprite 1 Answer
Blast Particle Not Spreading to Fullscreen 0 Answers
Particle Playback Error in 5.4 0 Answers