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 Jeremy 7 · Apr 16, 2011 at 04:43 AM · arrayparticleconvertemittergetcomponentsinchildren

An array for Particle Emitters?

I am trying to turn off multiple Particle Emitters in the children of an object at the same time using an array. I will be using the same code to turn them back on later, but I can't get either to work.

Here is the code I am using:

    var particleEmitters : ParticleEmitter[];
    particleEmitters = gameObject.GetComponentsInChildren(ParticleEmitter) as ParticleEmitter;
    for (var emitters : ParticleEmitter in particleEmitters)
    {
        emitters.emit = false;
    }

I get the following error message:

Cannot convert 'UnityEngine.ParticleEmitter' to 'UnityEngine.ParticleEmitter[]'.

Does this mean it is impossible to use an array for Particle Emitters? Or do I have something else set up incorrectly?

Comment
Add comment · Show 1
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 Ashkan_gc · Apr 16, 2011 at 05:06 AM 0
Share

the code seems completely okay to me!

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mortennobel · Apr 16, 2011 at 06:24 AM

You should cast the object returned by GetComponentsInChildren to ParticleEmitter[].

Like this:

var particleEmitters : ParticleEmitter[];
particleEmitters = gameObject.GetComponentsInChildren(ParticleEmitter) as ParticleEmitter[];
for (var emitters : ParticleEmitter in particleEmitters)
{
    emitters.emit = false;
}
Comment
Add comment · Show 2 · 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 Jeremy 7 · Apr 16, 2011 at 07:10 AM 0
Share

I tried this and it compiles but now I am getting an error on the line when I try to run:

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

Does this mean it is not seeing the particle emitters?

avatar image Jeremy 7 · Apr 16, 2011 at 07:29 AM 0
Share

Well, I did a check on the array and it seems like it is not grabbing my particle emitters when I am creating the array. This seems like a different problem and it seems you have solved my initial problem. Thank you!

avatar image
0

Answer by theropodx · Dec 28, 2012 at 10:53 PM

In case this helps someone, I got this working with this code (using #pragma strict):

 var particleEmitters : Component[];
 particleEmitters = transform.gameObject.GetComponentsInChildren(ParticleEmitter) as Component[];
 for (var emitters : Component in particleEmitters)
 {
    emitters.gameObject.particleEmitter.emit = true;
 }
Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

How can I solve my Mesh Particle Emitter problem? 1 Answer

Particle emitter works intermittently 0 Answers

ParticleSystem, Maintaining Particle position when emitter moves. 1 Answer

How do I generate - IN CODE - a ParticleSystem for static particles? 1 Answer

Importing .x file 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