Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Nitoken · Jan 26, 2016 at 07:46 PM · c#componentenableddisabled

Disabled script still working C#

Hey there. When I click on object and object's see = true script will run IF loop. It should run just once even when Object will be clicked 10 times(I want to prevent from decreasing move points in future). So at the end of IF loop i put code that should disable all script component in that gameobject. And it works. Script is disabled but... Still woring. Still i can click on object and script will decrease move points. sasiad is array with objects next to that object. Where I made mistake?

  void OnMouseDown()
     {
         if (see)
         {
             klikniety = true;
             gameCtrl.GetComponent<GameControl>().move -= 1;
             foreach (GameObject value in sasiad)
             {
                 if (value != null)
                     value.GetComponent<PoleControl>().see = true;
             }
             gameObject.GetComponent<PoleControl>().enabled = false;
         }
     }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Bunny83 · Jan 26, 2016 at 08:54 PM

The "enabled" state of a MonoBehaviour script only controls the execution of some method which are actually bound to that state. This includes Awake, Start, Update, LateUpdate, FixedUpdate. Most event based callbacks still work.

Comment
Add comment · Show 3 · 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 TheCuriousHobbyist · Apr 28, 2020 at 02:14 PM 0
Share

Why is Late Update STILL WORKING when enabled??

avatar image Bunny83 TheCuriousHobbyist · Apr 28, 2020 at 02:23 PM 0
Share

Uhm I don't quite understand your question. Of course LateUpdate works if the script is enabled. Do you mean when it's disabled? No, Unity will NOT call LateUpdate when the script instance is disabled. Are you sure you don't call it manually somewhere? If you do you should never do this to any of the Unity callbacks because it leads to such bugs / misbehaviour.


If you have an actual issue you want an answer for, please ask a seperate question. Show your code and what you have done already to debug the issue. Have you placed a Debug.Log inside LateUpdate? Have you checked the stacktrace?

avatar image puyehue · Nov 18, 2021 at 07:37 PM 0
Share

I understand that Awake still works when Script is disabled

avatar image
3

Answer by brunocoimbra · Jan 26, 2016 at 09:38 PM

Just add an if statement:

  void OnMouseDown()
  {
      if (!gameObject.GetComponent<PoleControl>().enabled)
      {
          return;
      }

      if (see)
      {
          klikniety = true;
          gameCtrl.GetComponent<GameControl>().move -= 1;
          foreach (GameObject value in sasiad)
          {
              if (value != null)
                  value.GetComponent<PoleControl>().see = true;
          }
          gameObject.GetComponent<PoleControl>().enabled = false;
      }
  }
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 FenixShadow · May 25, 2017 at 07:24 PM 1
Share

FYI you can also just use "enabled" as that will refer to the enabled property of the current script component.

avatar image
0

Answer by nikunjsth5 · Apr 15 at 02:54 AM

Never thought that OnCollision, OnTrigger and other functions work even if the script is disabled

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

69 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

.enabled Problems 1 Answer

C# GetComponent, component not turning off. 2 Answers

How do I disable Script on FP Controller? (Solved) 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