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 code-blep · May 12, 2013 at 01:06 PM · listcomponentenabled

BCE0019: 'enabled' is not a member of 'UnityEngine.Component' when using List

Hi,

I get this error when trying to enable/disable a script: BCE0019: 'enabled' is not a member of 'UnityEngine.Component'. The script I am trying to target is chosen from a List array.

I have learned that 'Component' does not have the function 'enabled' and I would normally use the name of the script itself to correct the problem as I am using #pragma strict. However I am having problems working out how to declare the script name when using a list array.

Here is some example code that works without pragma strict, but fails with it.

 #pragma strict
 import System.Collections.Generic;
 
 var addComponentsHere = new List.<Component>();
 
 function Start () {
     addComponentsHere[0].enabled = true;
     addComponentsHere[1].enabled = false;
     addComponentsHere[2].enabled = true;
 }

Thanks!

Paul

Comment
Add comment · Show 2
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 code-blep · May 12, 2013 at 01:42 PM 0
Share

Thanks robertu! That does indeed work. So should I just use lists using monobehaviour? The duality of both ways working is confusing me.

Also in further testing, it does not work if I try to change a value that is not part of monobehaviour. For example:

 addComponentsHere[0].Controller = controllerType;

Which gives the error 'Controller' is not a member of 'UnityEngine.$$anonymous$$onoBehaviour'.

avatar image robertbu · May 12, 2013 at 02:03 PM 0
Share

A quick check says the class hierarchy is:

Object->Component->Behaviour->$$anonymous$$onoBehaviour

and 'enabled' actually comes form Behaviour not $$anonymous$$onoBehaviour. So you could have a list of any one of these and the assignment (to the list) would work. It would have to be Behaviour or $$anonymous$$onoBehaviour for you to access 'enabled'. $$anonymous$$onoBehaviour makes the most sense to me for what you may be doing.

1 Reply

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

Answer by robertbu · May 12, 2013 at 01:24 PM

'enabled' comes from Monobehaviour, so how about a list of Monobehavours.

Comment
Add comment · Show 3 · 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 code-blep · May 12, 2013 at 02:24 PM 0
Share

O$$anonymous$$, I think I am getting the whole idea. So now I just get a warning: Implicit downcast from 'UnityEngine.Component' .... But it all works fine.

After searching my guess is to use: #pragma downcast after #pragma strcit to prevent the warning. If so does this reduce the efficiency of #pragma strict in any way?

avatar image robertbu · May 12, 2013 at 03:11 PM 0
Share

I don't know from personal experience, but according to a quick Google search, #pragma downcast just removes the downcast warning. But I also read that this may not be the best fix for the warning.

But the pragma may not be the best solution. In the examples I read about, they were getting the warning because they were using he string version of GetComponent() rather than passing the type. That is they were doing:

 GetComponent("$$anonymous$$yScript");

rather than:

 GetComponent($$anonymous$$yScript); 

This makes sense. In the former, the compiler does not know the type, so it must return a component. In the second case, the compiler will knows the type.

avatar image code-blep · May 12, 2013 at 03:13 PM 0
Share

Hi roberbu, yeah I read that as well but it does not seem to fit my scenario. $$anonymous$$y guess is that it is O$$anonymous$$. Thanks for all your help!

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

14 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

Related Questions

A node in a childnode? 1 Answer

How to Copy a Component if it contains List? 1 Answer

Removing a Component while in a List 1 Answer

.enabled Problems 1 Answer

How to read X and Y component ( of a vector2) from a list 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