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 ELISAN · May 21, 2015 at 10:36 AM · getcomponentcomponentenabled

enabled is not a member of UnityEngine.Component

I wanna enable some components by their name in inspector and this is my code:

 var Components : String[];
 
 function OnEnable () {
 for (var i= 0; i < Components.Length; i++){
 GetComponent(Components[i]).enabled = true;
 }

but I got this error:

enabled is not a member of UnityEngine.Component

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
1

Answer by fafase · May 21, 2015 at 10:46 AM

Component has no enabled member. It comes later in the hierarchy with Behaviour.

http://docs.unity3d.com/ScriptReference/Component.html

http://docs.unity3d.com/ScriptReference/Behaviour.html

Comment
Add comment · Show 4 · 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 ELISAN · May 21, 2015 at 12:39 PM 0
Share

"enabled" always worked for me, for example if I have a component with the name "Light" and I write this: GetComponent(Light).enabled = true; It will work. but in here I wanna add the name of components from inspector and it doesn't work

avatar image fafase · May 21, 2015 at 01:04 PM 0
Share

Ok I realize you are using the string version which only returns Component and requires a cast to the type. In general, the string parameter should be avoided and I think they even removed it from unity 5

avatar image ELISAN · May 21, 2015 at 01:32 PM 0
Share

$$anonymous$$aybe, but I'm using unity4.6... or maybe it's a bug!

avatar image ELISAN · May 21, 2015 at 04:57 PM 0
Share

Finally found the sollution :) with this code, you can enable or disable any components that you want:

 #pragma strict
 var ComponentToActive : String[];
 var ComponentToDeactive : String[];
 ////////////////////////////
 
 function OnEnable () {
     
 for (var i= 0; i < ComponentToActive.Length; i++){
 (GetComponent(ComponentToActive[i]) as Behaviour).enabled = true;}
 
 for (var j= 0; j < ComponentToDeactive.Length; j++){
 (GetComponent(ComponentToDeactive[j]) as Behaviour).enabled = false;}
      
     }
 

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

20 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

Related Questions

C# GetComponent, component not turning off. 2 Answers

How do I disable Script on FP Controller? (Solved) 2 Answers

Unable to get component from a gameobject 0 Answers

Unknown identifier when turning off SSAO through a JS script 1 Answer

How to Get TextMesh component from the Gameobject the script is attached to? 3 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