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 SHBelsky · Jul 30, 2013 at 09:36 PM · componentunity 4enableduntiy

'enabled' is not a member of UnityEngine.Component

I was working on a project before, saved it, and when I went to compile it I got this error. The line it is having a problem with is:

 script.enabled = false;

Every other time I ran it before, I never got this error. Nothing has changed from 2 days ago to now.

The full code this line is in is (it's a menu named "Dead," a menu shown for player death):

 var newSkin : GUISkin;
 var logoTexture : Texture2D;
 function theFirstMenu() {
     //layout start
     GUI.BeginGroup(Rect(Screen.width / 2 - 150, 50, 300, 200));
     //the menu background box
     GUI.Box(Rect(0, 0, 300, 200), "You died in the pit. You were *just* there.");
     //logo picture
     GUI.Label(Rect(15, 10, 300, 68), logoTexture);
     ///////main menu buttons
     //game start button
     if(GUI.Button(Rect(55, 50, 180, 40), "Start Over")) 
     {
            var script = GetComponent("Dead");
         Application.LoadLevel("gameFINAL");
         script.enabled = false;
     }
     //quit button
     if(GUI.Button(Rect(55, 150, 180, 40), "Main Menu")) 
     {
         Application.LoadLevel("titleFINAL");
     }
     //layout end
     GUI.EndGroup(); 
 }
 
 function OnGUI () {
     //load GUI skin
     GUI.skin = newSkin;
     //execute theFirstMenu function
     theFirstMenu();
 }

Hoping to resolve this error with the line. Thanks!

Comment
Add comment · Show 5
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 perchik · Jul 30, 2013 at 09:43 PM 0
Share

I don't know what your component named "Dead" is but it obviously does't have a .enabled property....

avatar image SHBelsky · Jul 30, 2013 at 09:50 PM 0
Share

It's the name of the script. I should have made that clear.

avatar image perchik · Jul 30, 2013 at 09:53 PM 0
Share

Right. I assumed as much. Your Dead script doesn't have an enabled property

avatar image SHBelsky · Jul 30, 2013 at 09:55 PM 0
Share

What code would I use, or where would I go to research on to implement that? Noob to Unity even now.

avatar image Eric5h5 · Jul 30, 2013 at 09:58 PM 0
Share

@perchik: no, all scripts (that can be attached to GameObjects anyway) have an enabled property, because they inherit from $$anonymous$$onoBehaviour, which inherits from Behaviour, which does have an enabled property.

2 Replies

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

Answer by Eric5h5 · Jul 30, 2013 at 09:56 PM

Don't use quotes in GetComponent, that makes it return Component (which does not have an enabled property as you can see in the docs) instead of your script type.

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 hoy_smallfry · Jul 30, 2013 at 10:08 PM

The error you are getting is popping up probably because you've added #pragma strict somewhere at the top, which enforces certain checks to happen.

According to the Unity documentation, GetComponent returns a Component type. If a string is used as the parameter, there is no hard script type to deduce the return type from, so it just returns a Component.

By looking at the list of members that `Component` has, you can see that there is no enabled member. If you are familiar with the concept of inheritance and polymorphism, you'll know that your Dead script has an enabled member because that member is inherited from `Behaviour`. But since you are receiving the dead script as a Component instead of a Dead type, which is earlier along the heirarchy, you cannot access it's enabled member while it's perceived as a Component.

You should explicitly state that var script is of type Dead by using the actual type instead of a string. This will make sure it returns a Dead type, like so:

var script = GetComponent(Dead);

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

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

18 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

Related Questions

Setting enabled on my objects children doesn't work 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Using a maze generator asset from asset store 0 Answers

AddComponent() causes a "trying to create a MonoBehaviour using the 'new' keyword" warning 2 Answers

Disabling GameObject doesn't disable components 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