• 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
Question by YoungDeveloper · Jan 05, 2014 at 04:11 PM · disableenabledbehaviour

Information about Behaviour.enabled

Hey there, I quick question.

If i disable script in Start() function like this.

 void Start(){
     GetComponent<MyScript>().enabled = false;
 }

What exactly it disables. All update functions like Update(), OnGUI(), OnTriggerEnter/Exit, OnCollision and all others, or just specific ones, thanks.

Comment

People who like this

0 Show 0
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
Best Answer

Answer by Invertex · Jan 05, 2014 at 04:14 PM

It disables the active part of the script. Functions can still be called externally. http://unity3d.com/support/documentation/ScriptReference/Behaviour-enabled.html?from=MonoBehaviour

Something like this you could have tested very quickly! And there are a few answered questions about this on here already ;)

Comment
YoungDeveloper
Bot123456

People who like this

2 Show 11 · 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 YoungDeveloper · Jan 05, 2014 at 04:18 PM 0
Share

I know that variables and function can still be called, that is why i am asking which "active" part, all, or something is still left to update.

avatar image Invertex · Jan 05, 2014 at 04:23 PM 0
Share

Nothing updates. No ONGUI, Update, Trigger, etc...

avatar image YoungDeveloper · Jan 05, 2014 at 04:27 PM 0
Share

Most script are plain methods and variables and called only when needed, without any needs to update anything. Couldn't that be a good practice to disable scripts that aren't in need in any updating to save those empty calls?

avatar image Invertex · Jan 05, 2014 at 04:39 PM 0
Share

You can just leave the update function out completely if you're not using it, it's not required. But if you want to stop a script from updating for a while, it's a nice choice instead of using a condition in the update itself.

avatar image Bunny83 · Jan 06, 2014 at 11:58 AM 1
Share

If you disable a script, the component itself doesn't fire any callbacks. However other components might fire some callbacks that belongs to them if your disabled script implements the callback. A common example is OnBecameVisible. It is fired from an attached renderer and will execute even when your script is disabled. Note: if the gameObject has been deactivated nothing will happen since the whole gameobject (including the renderer) is dead.

Update, FixedUpdate, OnGUI are not part of the MonoBehaviour base class. If they were you would have to override all the callbacks. You actually implement the callback "from scratch". Unity checks the compiled code (probably with reflection) to figure out which classes implement which callbacks. Based on this metadata Unity invokes the callbacks. So if you don't implement Update, Start, ... it won't be called.

Try this: Create an empty class (remove Start and Update) and attach it to a gameobject. Unity, at least in the older versions, even hides the enable/disable checkbox in the inspector since enabling wouldn't do anything. As soon as you add Start or Update the checkbox will reappear.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Disabling THIS script from code 1 Answer

Enabling/Disabling Multiple Tagged objects 1 Answer

Disalbe/Activate script if a key is pressed. 1 Answer

Reference script on Behaviour is Missing, but IT'S NOT MISSING 0 Answers

enable/disable specific components 3 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