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 Xdy · Apr 04, 2013 at 06:48 AM · bce0019

BCE0019: 'controlsEnabled' is not a member of 'UnityEngine.Component'

Error on 'controlsEnabled'

 function Start () {
     Player = GameObject.FindWithTag("Player");         
     mainCamera = GameObject.FindWithTag("MainCamera");
     weaponCamera = GameObject.FindWithTag("WeaponCamera"); 
     vehicleCam.camera.enabled = false;
     vehicle.GetComponent(VehicleControllScript).controlsEnabled = false;
     vehicleCam.GetComponent(AudioListener).enabled = false; 
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 Chronos-L · Apr 04, 2013 at 07:07 AM

Incorrect (Previous Answer)

GetComponent(type) or GetComponent(string) will return Component, you will need to cast it to do type-specific operation; in your case, setting the bool of a script:

Correction

GetComponent(string) will return Component, you will need to cast it to do type-specific operation; in your case, setting the bool of a script (Assume that it is named XYZ.js):

 ( vehicle.GetComponent("XYZ") as XYZ).controlsEnabled = false;

Or you can use GetComponent(type):

 vehicle.GetComponent(XYZ).controlsEnabled = false;

Another alternative is to use the generic GetComponent():

uJS

 vehicle.GetComponent.<XYZ>().controlsEnabled = false;

C#

 vehicle.GetComponent<XYZ>().controlsEnabled = false;



How to use the GetComponent (Example)

What will happen when I do this or that?*

UnityScript/uJS

You should not run the DataCheck.js as it is, you need to comment out everything but the line/snippet that you are interested in

Data.js

 #pragma strict

 public var data : int = 1;

DataCheck.js

 #pragma strict
 
 var gameObjectWithData : GameObject;
 
 function Start () {
     
 /* ====== Anonymous Variable/One-liner ====== */
     
     /* +++++++++ GetComponent( type : string ) +++++++++++++++++++++++++++ */
     
     /* - Compile error: data is not member of Component - */
     gameObjectWithData.GetComponent("Data").data = 9;
     
     /* - Okay - */ 
     (gameObjectWithData.GetComponent("Data") as Data).data = 9;
     
     /* +++++++++ GetComponent( type : Type ) +++++++++++++++++++++++++++ */
     
     /* - Okay - */ 
     gameObjectWithData.GetComponent(Data).data = 9;
     
     
     /* +++++++++ GetComponent<T>() +++++++++++++++++++++++++++ */
     
     /* - Okay - */ 
     gameObjectWithData.GetComponent.<Data>().data = 9;
     
 /* ====== Assignment ====== */
     
     /* +++++++++ GetComponent( type : string ) +++++++++++++++++++++++++++ */
     
     /* - x is considered a component, so this line is still okay - */
     var x = gameObjectWithData.GetComponent("Data");
     /* - Not okay, Compile error: data is not member of Component - */
     x.data = 9;
     
     /* - Warning: Implicit downcast from Component to Data - */
     var x : Data = gameObjectWithData.GetComponent("Data");
     x.data = 9;
     
     /* - Okay - */ 
     var x : Data = gameObjectWithData.GetComponent("Data") as Data;
     x.data = 9;
     
     
     /* +++++++++ GetComponent( type : Type ) +++++++++++++++++++++++++++ */
     
     /* - Okay - */ 
     var x  = gameObjectWithData.GetComponent(Data);
     x.data = 9;
     
     /* - Okay - */ 
     var x : Data = gameObjectWithData.GetComponent(Data);
     x.data = 9;
     
     /* +++++++++ GetComponent<T>() +++++++++++++++++++++++++++ */
     
     /* - Okay - */ 
     var x = gameObjectWithData.GetComponent.<Data>();
     x.data = 9;
     
     /* - Okay - */ 
     var x : Data = gameObjectWithData.GetComponent.<Data>();
     x.data = 9;
 }

C#

You should not run the DataCheckCS.cs as it is, you need to comment out everything but the line/snippet that you are interested in

DataCS.cs

 using UnityEngine;
 
 public class DataCS : MonoBehaviour {
     public int data = 1;
 }

DataCheckCS.cs

 using UnityEngine;
 
 public class DataCheckCS : MonoBehaviour {
     
     public GameObject gameObjectWithDataCS;
     
     void Start () {
 /* ====== Anonymous Variable/One-liner ====== */
         
     /* +++++++++ GetComponent( type : String ) +++++++++++++++++++++++++++ */
         
         /* - CS1061, UnityEngine.Component doesn't have `data` ... - */
         gameObjectWithDataCS.GetComponent("DataCS").data = 9;
         
         /* - Okay - */ 
         (gameObjectWithDataCS.GetComponent("DataCS") as DataCS).data = 9;
         ((DataCS)gameObjectWithDataCS.GetComponent("DataCS")).data = 9;
         
     /* +++++++++ GetComponent( type : Type ) +++++++++++++++++++++++++++ */
         
         /* - CS0119, expression denotes a `type` ... - */ 
         gameObjectWithDataCS.GetComponent(DataCS).data = 9;
         ( gameObjectWithDataCS.GetComponent(DataCS) as DataCS ).data = 9;
         ( (DataCS) gameObjectWithDataCS.GetComponent(DataCS)).data = 9;
         
         /* - CS1061, UnityEngine.Component doesn't have `data` ... - */
         gameObjectWithDataCS.GetComponent(typeof(DataCS)).data = 9;
         
         /* - Okay - */ 
         ( gameObjectWithDataCS.GetComponent(typeof(DataCS)) as DataCS ).data = 9;
         ( (DataCS) gameObjectWithDataCS.GetComponent(typeof(DataCS))).data = 9;
         
     /* +++++++++ GetComponent<T>() +++++++++++++++++++++++++++ */
         /* - Okay - */ 
         gameObjectWithDataCS.GetComponent<DataCS>().data = 9;
         
 /* ====== Assignment ====== */
     
     /* +++++++++ GetComponent( type : string ) +++++++++++++++++++++++++++ */
         /* - CS0226, Cannot implicitly convert type ... - */ 
         DataCS x = gameObjectWithDataCS.GetComponent("DataCS");
         
         /* - Okay - */ 
         DataCS x = gameObjectWithDataCS.GetComponent("DataCS") as DataCS;
         x.data = 9;
         
         /* - Okay - */ 
         DataCS x = (DataCS)gameObjectWithDataCS.GetComponent("DataCS");
         x.data = 9;
         
     /* +++++++++ GetComponent( type : Type ) +++++++++++++++++++++++++++ */
         /*Refer to Anonymous Variable/One-liner->GetComponent( type : Type )*/
         
     /* +++++++++ GetComponent<T>() +++++++++++++++++++++++++++ */
         /*Refer to Anonymous Variable/One-liner->GetComponent<T>()*/
     }
     
 }
 
Comment
Add comment · Show 20 · 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 Xdy · Apr 04, 2013 at 07:27 AM 0
Share

using uJS result:

The name 'VehicleControllScript' does not denote a valid type ('not found')

avatar image Chronos-L · Apr 04, 2013 at 07:54 AM 1
Share

If it is WehicleScript.js with a W, then the code would be:

 vehicle.GetComponent.<WehicleScript>().controlsEnabled = false;

 
avatar image Chronos-L · Apr 04, 2013 at 08:07 AM 1
Share

It does not affect using that one

I am not sure why it doesn't work. Can you make sure that your script looks somewhat like this:

WehicleScript.js

 var controlsEnabled : boolean = true;

 ...


The script you used in the question

... //This is no longer needed, just delete it var VehicleControllScript : String = "ScriptName"; ...

 function Start () {
    ...
    
    //in the <>, you insert the class name, which is not a variable, just type it in as it is
    vehicle.GetComponent.<WehicleScript>().controlsEnabled = false;
    
    ...
 }
avatar image Eric5h5 · Apr 04, 2013 at 08:21 AM 1
Share

This answer is incorrect, given that the question is using Unityscript, not C#. GetComponent does not return Component in Unityscript, unless you use strings. It returns the type of the component you're getting. Also, Unityscript doesn't do C#-type casting with "()", it uses "as". There's no reason to use the generic version of GetComponent in Unityscript, since the non-generic version does the same thing, except slightly faster and less ugly.

(Unless Xdy is using a version of Unity older than 3.4, in which case this answer is correct, but if so, there's really no reason for using such an old version of Unity at this point.)

avatar image Chronos-L · Apr 04, 2013 at 09:27 AM 1
Share

I made some premature assumptions when I saw vehicle.GetComponent(VehicleControllScript).controlsEnabled, I assumed that VehicleControllScript is the class name and I came to the conclusion that like GetComponent(string), GetComponent(type) also returns Component (I also check the Documentation, it is stated there that function GetComponent (type : Type) : Component). However, later, Xdy shows that the VehicleControllScript is in fact a string. So, I made a mistake on GetComponent(type).

I have to apologize for using () to cast, that wouldn't work in uJS, its been a while since I wrote in uJS.

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

13 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

Related Questions

Android BCE0019 error with UnityEngine 1 Answer

Ani.Mate error when port a PC game to iPhone 2 Answers

enabled doesnt work iPhone 1 Answer

BCE0019: 'height' is not a member of 'UnityEngine.Collider'. 2 Answers

Enabling / Disabling C# Scripts - Why am I getting the error "not a member of 'UnityEngine.Component'"? 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