- Home /
Resetting non-looping particle system
I have a gun that shoots GameObjects (non-hitscan bullets). I'm precaching all the bullets (the gun has a maximum range, so I just instantiate as many bullets as it can possibly fire at once), and want to do the same with the bullets' fancy particle impact effects. Each impact effect is a non-looping particle system, which refuses to play more than once regardless of what I do. I've tried activating/deactivating the gameObject it's attached to, setting enableEmission=true/false, and setting particleSystem.time back to 0 (and various combinations of the three). Nothing seems to work. I don't want to loop the particle systems because that creates weird effects and makes more work for my artist (who would have to remember the lifetimes of the particleSystems and enter them manually into the precache manager component).
tl;dr: How to make a loop=false particle system reset and play more than once.
Answer by dreasgrech · Jul 24, 2014 at 11:24 PM
Call particleSystem.Clear() to reset your particle system, and then particleSystem.Play() to play it again.
Answer by Calos1591 · Jul 30, 2016 at 10:06 PM
GameObject_ParticleSystem.SetActive(false); GameObject_ParticleSystem.SetActive(true);
Works for me Unity 5.3.2
Answer by JonnyHilly · Aug 30, 2012 at 07:07 AM
particleEmitter.emit = true;
particleEmitter.Emit();
particleEmitter.emit = false;
:)
Answer by alternative_richie · Dec 22, 2015 at 11:10 AM
The above answers didn't work for me so I used this to restart it :-
http://docs.unity3d.com/ScriptReference/ParticleSystem.Simulate.html
ParticleSystem.Simulate(0.0f,true,true);
Previously I had done it by using SetActive(false) on the GameObject when the particle finished playing and then SetActive(true) when I wanted to play it again. This worked and restarted the particle. But I thought this was inefficient so am now using emission.enabled true and false and Simulate to restart it, keeping the GameObject itself active.
Answer by Hrusilov · Feb 10, 2016 at 05:39 PM
I wanted to emit some particles for shooting and had to do this:
GetComponent<ParticleSystem>().Clear();
GetComponent<ParticleSystem>().Simulate(GetComponent<ParticleSystem>().duration);
GetComponent<ParticleSystem>().Play();
I have the shooting script attached to the same game object as particle system.