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 Lemo76 · Dec 10, 2014 at 06:51 AM · javascripterrorgetcomponentgetcomponents

[JS] - GetComponents (No appropriate version)

So I've got multiple components attached to a gameobject called 'Gun_Module' and I'm going to make an array and search through the array and switch off specific ones.

 private var Gun_Module : Component;
 private var GunScripts : Component[];
 
 GunScripts = GetComponents(Gun_Module);

The error is that it says:

 "No appropriate version of 'UnityEngine.Component.GetComponents' for the argument list '(UnityEngine.Component)' was found."

Help would be greatly appreciated!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by taxvi · Dec 10, 2014 at 07:01 AM

ok, i guess Gun_Module is your class right? than it can not be a name of a variable, rather try this:

   private var GunScripts : Gun_Module[];
   
   GunScripts = GetComponents(Gun_Module);
 
Comment
Add comment · 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 Lemo76 · Dec 10, 2014 at 07:19 AM 0
Share

It states the name 'Gun_$$anonymous$$odule' does not denote a valid type ('not found')

avatar image taxvi · Dec 10, 2014 at 07:35 AM 0
Share

oh, I just noticed that you said Gun_$$anonymous$$odule is a gameObject, I thought it was a name of the script. thing is, by using GetComponents() you can not retrieve all the components of the gameObject, but rather retrieve only the components of SPECIFIC type. Like, if your object has two colliders attached to it than GetComponent(Collider) will give you all the Colliders of the object. but each script attached to the game object is of a separate type. Like if you have two scripts on your enemy called Defense$$anonymous$$odeScript and Attack$$anonymous$$odeScript you need to call the GetComponents() once for each script. I'd also advise you to use the gameObject.GetComponent ins$$anonymous$$d, like:

 myComponent1 = myGameObject.GetComponent(myScriptname1);
 myComponent2 = myGameObject.GetComponent(myScriptname2);
 ...
 etc.

I know it's a little pain in the ass but this is the best solution I can think of.

avatar image Lemo76 · Dec 10, 2014 at 07:41 AM 0
Share

hmm, thanks for the long response but the 'Gun_$$anonymous$$odule' is the name of the script. There are multiple 'Gun_$$anonymous$$odule' scripts attached to the single gameObject. This single gameObject has this script which searches through the array. :/ I'm a bit stumped at this. Also, why would it say it does not denote a valid type 'not found'?

Thanks for the help so far.

avatar image taxvi · Dec 10, 2014 at 07:45 AM 0
Share

than it should work fine, no clue what's wrong with it :|

avatar image taxvi · Dec 10, 2014 at 08:48 AM 1
Share

nice, good to know such stuff, I just gained a better understanding how to integrate C#/JS scripts better :))

Show more comments

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

I can do this in JS or not ??? 2 Answers

What will happen if I GetComponent in this way? (Example) 1 Answer

Error: not a member of 'UnityEngine.GameObject[]'. 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