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 11, 2013 at 09:16 PM · errorcomponentenablepragma strict

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

Hi,

I get this error when trying to enable/disable a script: BCE0019: 'enabled' is not a member of 'UnityEngine.Component'.

I know that this is because I am trying to use #Pragma Strict but cannot work out that right way to do it.

Here is an example code:

 #pragma strict
 var movementScript : Component; //I drag and drop the selected script in the inspector
 
 function Start () {
     movementScript.enabled = true;
 }

It seems like such a simple problem but I just can't seem to work it out.

Thanks!

Paul

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

4 Replies

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

Answer by Eric5h5 · May 11, 2013 at 10:08 PM

Component has no .enabled property. Instead of that, use the name of your script.

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 code-blep · May 11, 2013 at 10:25 PM 0
Share

I had no idea you could setup a drag and drop component variable that way Eric5h5! Thank you once again!

avatar image code-blep · May 12, 2013 at 01:10 AM 0
Share

Can you also explain how I can take a similar approach with this please Eric5h5?

 var controllers = new List.<Component>();
avatar image Eric5h5 · May 12, 2013 at 02:00 AM 0
Share

I'm not quite sure what you're asking, though it might be better if you started a new question for that.

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

No problem Eric5h5, will do! Thanks.

avatar image
0

Answer by seejayjames · May 11, 2013 at 10:53 PM

// Edit: This is for accessing scripts attached to other GameObjects //

If you get it from a GameObject, the .enabled works:

myGameobjectName.GetComponent(myScriptName).enabled = true;

So at the top, you can use

var myGameobjectName : GameObject;

and if you want to set it without needing to use the Inspector, use this in your Start () function:

myGameobjectName = GameObject.Find("actual_name_of_gameobject_in_hierarchy");

So, myGameObjectName is now a variable which holds a reference to the GameObject. (Do the "Find" in Start() not Update() because it's expensive.) Then you can use myGameObjectName.GetComponent(name_of_component) to access scripts or other components attached to that GameObject.

For example, to change the variable "power" in your script, use:

myGameobjectName.GetComponent(myScriptName).power = 74;

Or to see if a Boolean (like playerAlive) in the script is currently true or false, use:

if (myGameobjectName.GetComponent(myScriptName).playerAlive == false) { start_funeral(); }

// sorry so morbid... ;)

Comment
Add comment · Show 1 · 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 Eric5h5 · May 11, 2013 at 11:03 PM 0
Share

You misunderstand; .enabled is not a member of Component, and it doesn't have anything to do with "getting it from a GameObject". What you're doing isn't related to the question since you're not using Component. If you used quotes in GetComponent in order to make it return Component ins$$anonymous$$d of the type, then .enabled would not work.

avatar image
-1

Answer by Btrad · May 11, 2013 at 10:56 PM

 var script : movementScript; 
 
 function Start() 
 {
 movementScript = GetComponent(movementScript); 
 movementScript.enabled = false;
 }
 
Comment
Add comment · 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
-1

Answer by EAST West Side · Jan 27, 2016 at 03:18 PM

In school I have this problem and I can't seem to get it to work again. I imported a asset and it said I had something wrong with the mouse look script, so I deleted the imported asset and it still said:

Assets/Standard Assets/Character Controllers/Sources/Scripts/MouseLook.cs(61,35): error CS1061: Type UnityEngine.Component' does not contain a definition for freezeRotation' and no extension method freezeRotation' of type UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

Comment
Add comment · Show 1 · 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 Bunny83 · Jan 27, 2016 at 05:09 PM 0
Share

First of all this is not an answer but you posted this as one.

Second you didn't include your actualy script which you have problems with. Since the $$anonymous$$ouseLook script is part of the standard assets it might simply be the case that you use an outdated version of the script.

Anyways, next time when you want to ask a question, post an actual question and not an answer to another question. Also describe your problems as detailed as possible and include the code which produces the error.

Finally according to the FAQs UnityAnswers is not there so others can fix your syntax / compiler errors,

I usually don't use the $$anonymous$$ouseLook script, but if i remember correctly, the old version contained something like this inside Start:

 void Start()
 {
     if (rigidbody)
         rigidbody.freezeRotation = true;
 }

Since the shortcut properties like "rigidbody" has been deprecated you have to use GetComponent to get the Rigidbody reference. Something like:

 void Start()
 {
     Rigidbody rb = GetComponent<Rigidbody>();
     if (rb != null)
         rb.freezeRotation = true;
 }

However this is usually an "Unity upgradeable". When you import a package with a script like that it should ask you if you want to upgrade it in which case Unity would replace rigidbody with GetComponent<Rigidbody>()

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

Animation event 'new event' has no receiver 1 Answer

How to select BoxColliders of children and disable them? 1 Answer

An instance of type 'UnityEngine.Component' is required to access non static member 1 Answer

Collider.enabled working differently from inspector? 1 Answer

Menu Component/MaterialUI/EZAnim can't be checked because doesn't exist 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