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
1
Question by Steve Edwards · Jan 14, 2011 at 12:01 PM · enabled

What does 'enabled' do in isolation within a script?

Hi

In the MachineGun script from the Unity FPS tutorial is this line:

enabled = false;

I looked in the script reference and found this:

"Behaviour.enabled Enabled Behaviours are Updated, disabled Behaviours are not."

Does this mean that the Update(), FixedUpdate() and LateUpdate() functions are not called within only the script in which that line appears? Or, as Behavior is a super-class, is it affecting other scripts attached to the parent object?

Thanks

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
1
Best Answer

Answer by Statement · Jan 14, 2011 at 12:13 PM

It affect only the instance. If a game object have several behaviors, disabling one will not affect the others. If you have a script and write enabled = false; it will only disable the script that is running. Other scripts will remain enabled. To disable another script, you should set enable on that particular instance instead. renderer.enabled = false; for example turns off the renderer.

There is also gameObject.active which disable the game object and any components attached to it.

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 Steve Edwards · Jan 14, 2011 at 12:21 PM 0
Share

Thanks Statement. If a script can disable itself this way, how do you re-enable it then? Surely as the script is no longer running, having "enabled=true" will never be called?

avatar image Statement · Jan 14, 2011 at 12:53 PM 0
Share

Sort of true. Some functions are still called even if it's disabled. Check the manual which functions this applies to. IIRC collision events are still sent. You can use another object to enable something. IIRC Invoke functions run even though object is disabled.

avatar image Statement · Jan 14, 2011 at 12:54 PM 0
Share

IIRC InvokeRepeating can be used to check for some condition is met, to re-enable the object.

avatar image Steve Edwards · Jan 14, 2011 at 01:18 PM 0
Share

Thanks, InvokeRepeating is really useful. Looking through the manual it seems most functions except Late/Fixed/Update are still called.

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

No one has followed this question yet.

Related Questions

gameObject.GetComponent("Script").enabled = true not working 5 Answers

Enable script on parent 2 Answers

Information about Behaviour.enabled 1 Answer

Errors when trying to enable script on gameobject. 0 Answers

Script keeps functioning when disabled 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