• 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 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

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

1 Reply

  • Sort: 
avatar image

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

People who like this

0 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_Module' 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_Module 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 DefenseModeScript and AttackModeScript you need to call the GetComponents() once for each script. I'd also advise you to use the gameObject.GetComponent instead, 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_Module' is the name of the script. There are multiple 'Gun_Module' 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

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

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

Script not working (Java script) 2 Answers

BCE0019: 'Add' is not a member of 'UnityEngine.Transform[]' 1 Answer

Problems with creating custom EditorGUI for script 0 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