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
2
Question by PixelPaw · Aug 04, 2013 at 01:47 PM · componentenabled

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

I'm trying to enable / disable a script on a different gameObject's script ...

Looked on all the posts on the forum about the subject and tried about everything suggested and nothing works..

Heres the problem :

So to access and enable the script on the GameObject I use: GameObject.Find(the gameObject).GetComponent(the script).enabled = true;

but then I get this : BCE0019: 'enabled' is not a member of 'UnityEngine.Component'.

So on the forums some say to use active instead of enabled... then I get this :

BCW0012: WARNING: 'UnityEngine.Component.active' is obsolete. the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead.

sigh

I get : BCW0012: WARNING: 'UnityEngine.GameObject.active' is obsolete. GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.

Seriously it tells me to use something that is Obsolete , anyways so I use (even if its no longer a component... GameObject.SetActive(),

result : BCE0049: Expression 'GameObject.Find(GameObject).GetComponent(Script).gameObject.SetActive' cannot be assigned to.

No surprise there.

So how do you enable / disable a script from another gameObject's script ...??? ty!

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

2 Replies

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

Answer by aldonaletto · Aug 04, 2013 at 02:37 PM

Despite being a little surprised, I confirmed that there's no enabled property in the Component base class! That's weird, because its descendants usually have such property. Anyway, you can use the typed version of GetComponent instead of the string version:

 GameObject.Find("someObject").GetComponent(ScriptName).enabled = true;

ScriptName in this case must be replaced by the script class name, which is the script filename without extension. If the script is "PlayerHealth.js", for instance, its class is PlayerHealth:

 GameObject.Find("someObject").GetComponent(PlayerHealth).enabled = true;

Using the string version of GetComponent is only recommended when the compiler doesn't know the script class - it has not been compiled yet, is in a different language or will be defined by a string assigned at runtime. If you really need to use the string version, then coerce the type to MonoBehaviour, which is the "mother of all scripts" and has the enabled property:

 (GameObject.Find("someObject").GetComponent("ScriptName") as MonoBehaviour).enabled = true;

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 PixelPaw · Aug 04, 2013 at 03:39 PM 0
Share

Well I just followed your first example seems that my problem was that I entered the GetComponent (*) in quotes and that was the problem !

Thanks for your answer really appreciate it !!!

avatar image HeineTech · Mar 24, 2015 at 12:55 AM 1
Share

I have spent hours researching this simple mechanic as well. Thanks so much!

avatar image GAZEREAPER · Mar 29, 2015 at 10:56 AM 0
Share

wow, you're my hero dude, using as $$anonymous$$onoBehaviour worked! :D thanks mate

avatar image trevoedwards · Apr 02, 2015 at 01:14 AM 0
Share

Using $$anonymous$$onoBehaviour worked like a charm for me too. Thanks a bunch!

avatar image
1

Answer by furic · Apr 02, 2015 at 01:30 AM

Make sure your script is defined as:

 using Unity.Engine;
 using System.Collections;
 
 public class MyScript : MonoBehaviour
 {
 
 }

MyScript should always be derived from MonoBehavious or any parent class derived from MonoBehavious

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

16 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

Related Questions

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

Why wont this work? (I've done similar 1000 times fine) 1 Answer

Yet another NullReferenceException question. 2 Answers

Problems deactivating a script. 1 Answer

How to get a value from an array within another script. 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