- Home /
Particle system stop?
Hello,
I'm just using one of the unity built in particle effects, the soap bubbles but can't get the particles to stop playing. I had this working in another project so I'm not sure if the more recent version of Unity has affected this.
I tried applying this script to the particle system:
using UnityEngine;
using System.Collections;
public class Bubbles : MonoBehaviour
{
void Start ()
{
particleSystem.Stop();
}
}
I Get the error:
NullReferenceException: Object reference not set to an instance of an object UnityEngine.ParticleSystem.Stop (Boolean withChildren) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/ParticleSystemBindings.cs:496) UnityEngine.ParticleSystem.Stop () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/ParticleSystemBindings.cs:488) Bubbles.Start () (at Assets/Bubbles.cs:9)
Answer by justinl · Jul 09, 2013 at 10:19 PM
Your script doesn't have reference to the particle system. Create add this public variable to the top of your script.
public ParticleSystem particleSystem;
and then drag the particle system into that Bubbles script in the Inspector.
I tried exactly that, but it doesn't let me drag the particle system into the inspector slot. As if it doesn't recognise it, even when I search for it using the node at the side.
I presumed you meant "ParticleSystem" with an "e" at the end. I'm not sure what else to try.
public ParticleSystem particleSystem;
I'm not sure of your particular setup but that's how it's supposed to work. I've done this many times before. Are there any errors in your console? Also, you cannot select the script in your Project window and then drag the particle system onto the script's slot in the inspector. You need to assign that Bubbles script to a GameObject first. THEN you can drag it onto that instance of the script which is on the GameObject
Thanks for the advice again, I know you can't drag a particle onto an asset directly in the project window, I was trying it on the $$anonymous$$ain Camera, Particle system itself and an empty game object with the particle parented. For some reason when I've tried again with:
using UnityEngine;
using System.Collections;
public class Bubbles : $$anonymous$$onoBehaviour
{
public ParticleSystem particleSystem;
void Start ()
{
particleSystem.Stop();
}
}
I get a null reference again.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.ParticleSystem.Stop (Boolean withChildren) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/ParticleSystemBindings.cs:496)
UnityEngine.ParticleSystem.Stop () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/ParticleSystemBindings.cs:488)
Bubles.Start () (at Assets/Bubles.cs:10)
I also get this message when I save the code from $$anonymous$$onoDevelop.
Assets/Bubles.cs(6,31): warning CS0108: `Bubles.particleSystem' hides inherited member `UnityEngine.Component.particleSystem'. Use the new keyword if hiding was intended
So you have a $$anonymous$$ainCamera in your scene. That $$anonymous$$ainCamera has the Bubbles.cs script attached to it. Then you have a particle system in the scene, and you drag that particle system onto the bubbles.cs instance on the $$anonymous$$ainCamera? Is that about right? (Also I notice that your errors reference "Bubles" but the class you've copy/pasted is "Bubbles" with 2 "b"'s. Not sure if that's a typo...
That is correct, yes. "Bubles" was just my input error when I was replying. I was going to mention that but I forgot! :(
Answer by SpeedTutor · Jul 10, 2013 at 05:58 PM
Thanks for the advice again, I know you can't drag a particle onto an asset directly in the project window, I was trying it on the Main Camera, Particle system itself and an empty game object with the particle parented. For some reason when I've tried again with:
using UnityEngine;
using System.Collections;
public class Bubbles : MonoBehaviour
{
public ParticleSystem particleSystem;
void Start ()
{
particleSystem.Stop();
}
}
I get a null reference again.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.ParticleSystem.Stop (Boolean withChildren) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/ParticleSystemBindings.cs:496)
UnityEngine.ParticleSystem.Stop () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/ParticleSystemBindings.cs:488)
Bubles.Start () (at Assets/Bubles.cs:10)
I also get this message when I save the code from MonoDevelop.
Assets/Bubles.cs(6,31): warning CS0108: `Bubles.particleSystem' hides inherited member `UnityEngine.Component.particleSystem'. Use the new keyword if hiding was intended
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can you still not change the Velocity of spawned particles? 2 Answers
Flip over an object (smooth transition) 3 Answers