Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Dubious-Drewski · Sep 27, 2012 at 06:51 AM · componentaccess

Very simple component-access question

I create a cube. I add a particle emitter component. (I click on Component/Effects/Particle System) I change nothing else. I add this script to the cube:

 function Start () {
     gameObject.particleEmitter.emit = false;
 }

It should instantly turn off the emitter. Seems simple, but when I run this, I get the following error:

MissingComponentException: There is no 'ParticleEmitter' attached to the "TestBox" game object, but a script is trying to access it.

I don't understand, because there is clearly a particle emitter component attached to this cube. Why is Unity claiming there isn't?

EDIT:

I forgot there is the new particle system, so I changed it to particleSystem instead:

 function Start () {
     gameObject.particleSystem.emit = false;
 }

But it just gives me the error:

'ParticleSystem' is not a member of 'UnityEngine.GameObject'. Did you mean 'particleEmitter'?

What what what?!?!!

Comment
Add comment · Show 5
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 Dubious-Drewski · Sep 27, 2012 at 07:15 AM 0
Share

Yes, I forgot about GetComponent, thank you. I tried this:

 gameObject.GetComponent(ParticleEmitter).emit = false;


But I just got this error:

 NullReferenceException: Object reference not set to an instance of an object

I cannot believe how hard a time I am having with this. I've accomplished a lot in Unity so far, but I've been trying to figure out this simple problem for literally weeks. It HAS to be simple! What am I doing wrong?

EDIT:

Here is a screenshot of the whole setup:

http://i.imgur.com/jalZA.png

avatar image Dubious-Drewski · Sep 27, 2012 at 07:44 AM 1
Share

Ahha!

     gameObject.GetComponent(ParticleSystem).enableEmission = false;

This is it! This is the code that does it! Thank you so much for your help, but I've finally solved this! Oh my God that was embarrassingly difficult!

avatar image Fattie · Sep 27, 2012 at 08:09 AM 1
Share

also

http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.html

"variables' section ..

avatar image Dubious-Drewski · Sep 27, 2012 at 08:13 AM 0
Share

Thank you. That was the page that helped me find the answer.

Why did you delete your previous comments? I'm just curious.

avatar image Fattie · Sep 27, 2012 at 08:22 AM 0
Share

hooray!

Good question ... I always delete comments (and questions) that become irrelevant. This site has way, way too much rubbish on it.

Since you completely solved your problem, and you stated the solution (for anyone in the future), I just deleted my cruft.

Rock On !!!

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Access to variables from other script objects 3 Answers

Unity crashes when accessing a function of a script from another script 2 Answers

Declare Component type in GetComponent 2 Answers

Can I access components scripts? 3 Answers

Painted Tree's Script Component 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