• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by SpeedTutor · Jul 09, 2013 at 09:21 PM · c#particlewont stop

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)

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

  • Sort: 
avatar image

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.

Comment
hdnn

People who like this

1 Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SpeedTutor · Jul 10, 2013 at 10:09 AM 0
Share

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;
avatar image justinl · Jul 10, 2013 at 04:56 PM 0
Share

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

avatar image SpeedTutor · Jul 10, 2013 at 05:21 PM 0
Share

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
avatar image justinl · Jul 10, 2013 at 06:34 PM 0
Share

So you have a MainCamera in your scene. That MainCamera 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 MainCamera? 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...

avatar image SpeedTutor · Jul 10, 2013 at 11:48 PM 0
Share

That is correct, yes. "Bubles" was just my input error when I was replying. I was going to mention that but I forgot! :(

Show more comments
avatar image

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
Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Palta · May 27, 2015 at 09:54 AM

GetComponent().Stop(); GetComponent().Play();

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Instantiation Wont Stop 1 Answer

c# enum wont show in inspector 3 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges