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 naqvir · Apr 04, 2012 at 05:33 AM · gameobjectparticlescompilingcompile-errorparticleemitter

Compilor Error - Adding a new ParticleEmitter to the object

Hi everyone can someone explain to me why this does not compile.

 private function generateNewParticles(chosenComponent:ParticleEmitter)
 {                
     Destroy(selectedEntityObject.GetComponent(ParticleEmitter));
     selectedEntityObject.AddComponent(chosenComponent);
 }

It says that " No appropriate version of the AddComponent for argument list with ParticleEmitter". I dont understand why this doesnt work because ParticleEmitter is a component. :S

Furthermore chosenComponent is an variable passed through as a component type. However if i were to do this:

 print(typeOf(chosenComponent));

It would output "ParticleEmitter" in the console.

Thanks in advance

Comment
Add comment · Show 12
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 hijinxbassist · Apr 04, 2012 at 05:40 AM 0
Share

I think its because you are trying to add a particle emitter as a component. First add the ParticleEmitter component, you can try using the chosenComponent's Type for the AddComponent function. At this point, you could really just say AddComponent(ParticleEmitter). Once the component is there, you can say

 selectedEntity.GetComponent(ParticleEmitter).particleEmitter=chosenComponent;

You are passing 'a' particle emitter, not the system type.

avatar image naqvir · Apr 04, 2012 at 05:47 AM 0
Share

Isnt a ParticleEmitter a component? i checked the API and it inherits from Component Class. :s Sorry im afraid i dont fully understand your explanation. Can i not destroy the original particle emitter on the object, then add a new one using the AddComponent function? Also if i just insert ParticleEmitter in the param of AddComponant, how will it know what that points to since its only a type,and also not identifying a variable , in this case chosenComponent..

avatar image naqvir · Apr 04, 2012 at 05:51 AM 0
Share

ahhhhh i seee what you did there, i didnt realise that particle emitter was actually a field in ParticleEmitter Script.

avatar image naqvir · Apr 04, 2012 at 05:52 AM 0
Share

ok now , i tried it and it says it is read only now :S

avatar image hijinxbassist · Apr 04, 2012 at 05:52 AM 0
Share

if you want to pass a Type, i think it would have to be type System(i may be wrong here). Think about it this way.

If you overload that function with a different component type, say a String, then it already breaks the overload since it expects a ParticleEmitter. So if you only want to pass the component type, this would not be the way to go about it. What you are passing in the overload would be a specific particle emitter, the type is already declared.

Currently you can pass a chosen particle emitter from somewhere else into your function. You dont need to get rid of the Component itself, you would just be changing the paricle emitter attached to the component

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Laser Beam in Unity 0 Answers

Particle Rigid Body Dynamics without using rigid body dynamics 0 Answers

Use animated prefab model as a mesh in a particle system? 1 Answer

How to simply enable an objects particle system emission when that object collides with another? 1 Answer

How to change particles' view? 2 Answers


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