Turning the Particle System on and off

I would like to be able to turn off a Particle System when a user is not using thrust. I am using the Particle System's GameObject.active to do this. It works but when I set it to true again, particles will appear at the location where it was set to False (until their lifespan ends).

Is there a better way to enable/disable a Particle System?

7 Answers

7

Use GameObject.particleEmitter.emit = true;

EDIT By Meltdown :

The above line of code is only applicable to the legacy particle system, and should no longer be used.

The correct way to turn a particle system on and off is the following…

ParticleSystem.Play() - Start emitting from the particle system

ParticleSystem.Stop() - Stop emitting from the particle system

Note : You should not make a particle system active or inactive using SetActive(bool), as essentially any existing particles will just dissapear or re-appear, which looks unnatural. Using Play() or Stop() as above, will stop emitting, but keep showing any particles that are still within their life span.

Works great, thanks!

cool, vote up plz ;).

Edited original post with more up to date stuff ;)

Sorry for the necro on this thread. However when you google “disable particle system unity” this page is top so I am assuming it is a very looked at page.

Anyways, with Unity5 the documentation has changed a little bit for those using the .GetComponent() function of the GameObject class in c#.

Use this instead:

gameObject.GetComponent<ParticleSystem>().enableEmission = false;

Again, sorry for the necro but I hope this helps some people!

Cheers,
Swirllyman

I dont understand, can you explain it a bit?

Sure, when you are calling GetComponent() in Unity, you are looking for a specific type of data you want to manipulate whether that is an existing script or an existing component. Unity has built in Particle Systems so to access them directly. You need to call the GetComponent<>() function on your Game Objects in order to access them though. If you are still confused I highly reccommend checking out : http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html

How come when i copy and paste your script it gives me an error? (I made the game obj a variable) sry im kind of new to scripting. :/

if( ActivatePower == true ){ if( PowerActive > 0 ){ PowerParticles.GetComponent<ParticleSystem>().enableEmission = true; Damage = 40; Force = 250; } This is the script im using and i want to make it emit particles when this happens

So the code I had posted was for c#. You are programming in JavaScript, technically UnityScript. Try using this syntax instead: PowerParticles.GetComponent(ParticleSystem).enableEmission = true; Or: PowerParticles.GetComponent("ParticleSystem").enableEmission = true; or finally: PowerParticles.GetComponent("Particle System").enableEmission = true;

The correct way to turn a particle system on and off is the following…

ParticleSystem.Play() - Start emitting from the particle system

ParticleSystem.Stop() - Stop emitting from the particle system

Note : You should not make a particle system active or inactive, as essentially any existing particles will just dissapear or re-appear, which looks unnatural.

None of the things listed here worked for me, so I played around a bit and got this:

Call ParticleSystem.Play() to play it

Call ParticleSystem.Pause() to pause it.
NOTE: The Pause() method stops all particles, and they just end up freezing where they were. If you wanted them to go away completely, also call ParticleSystem.Clear()

This. This is what I needed. Thank you!

In case anyone is still looking for this, particle.enableEmission is now deprecated, we need to use
varForParticles.emission.enabled = false;

[dupe] [delete]

I used this… (C Sharp):

ParticleSystem particle = (ParticleSystem)gameObject.GetComponent("ParticleSystem");
particle.enableEmission = false;

this worked perfectly for my problem. thanks for this post.