Search Unity

Question Keep remaining particles alive after disabling particle component

Discussion in 'Editor & General Support' started by xDayhawk, Oct 5, 2020.

  1. xDayhawk

    xDayhawk

    Joined:
    Jun 24, 2020
    Posts:
    57
    Hi,

    I have a very basic GameObject that has a particle effect on it, sort of guns that keep firing.
    i've added support for a fire button (left mouse button) that when its pressed the GameObject becomes Active and then of course it starts firing, but when the mouse button is let go the GameObject becomes Deactivated and the guns stop firing.

    its working great, but what i've noticed is that if i press it for 2 seconds a lot of particles go out and as soon as i let it go and its becoming disabled, instead of just "stop firing new particles" , all the ones that i've shot out disappear instantly... im aware this is because i've disabled it, but is there a way i can keep the particles that are already "outside" on till they die or hit something?

    it looks really weird that they suddenly just disappear...

    Thanks in advance,
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    The only way I know of is not to disable the gameobject.

    Instead, use the Stop function on the particle system. It has a parameter to keep existing particles alive.
     
    karl_jones likes this.
  3. xDayhawk

    xDayhawk

    Joined:
    Jun 24, 2020
    Posts:
    57
    @richardkettlewell thank you! :)
    I'm a starting dev, i didnt think about that, and it works like a charm!

    it didnt work at first, with a small google i found that since its running every frame i should be checking if its already playing, so using isPlaying before makes it work gret.

    Thanks again for the response (and the response speed!)
     
    richardkettlewell likes this.