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
13
Question by Alexis816 · Apr 25, 2014 at 07:49 PM · inspectorcomponentscross

Cannot enabled / disable a script component?

The "X" which is used in the components (Inspector) to enable or disable is gone for my DestroyByContact script.

Which means I can't disable it!

Even if i don't especially need to disable it, i'd like to know why it do that.

Thank you for reading :)

 using UnityEngine;
 using System.Collections;
 
 public class DestroyByContact : MonoBehaviour
 {
     public GameObject explosion;
     public GameObject playerExplosion;
     void OnTriggerEnter(Collider other) 
     {
         if (other.tag == "Boundary") { return;}
         if (other.tag == "Player")
             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
         Instantiate(explosion, transform.position, transform.rotation);
            Destroy(other.gameObject);
         Destroy(gameObject);
     }
 }
 

And what i got in the editor:

alt text

capture d’écran 2014-04-26 à 09.43.48.png (23.6 kB)
Comment
Add comment · Show 1
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 Fattie · Feb 05, 2016 at 12:00 AM 0
Share

Nicely written question. I sent reward points.

2 Replies

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

Answer by Bunny83 · Apr 26, 2014 at 09:49 AM

Well, that's simply because your script doesn't have anything that can be disabled. The enabled property only affects the calling of Start, Update, FixedUpdate and OnGUI. Most callbacks are executed anyways. Unity only shows the enabled checkbox when the script has one of the above mentioned methods.

Since you only have an OnTriggerEnter method there's nothing to "disable" in this script. Most of the other callbacks are invoked by other components. For example all the OnCollision / OnTrigger messages are sent by a Rigidbody component, OnBecameVisible is sent by the renderer component, OnPostRender is sent by a Camera.

You can't really disable the whole script. The only way to do something like that is either:

  • Removing the script (with Destroy)

  • deactivating the gameobject by calling SetActive(false). However that would of course deactivate everything on the gameobject.

Comment
Add comment · Show 9 · 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 getyour411 · Apr 25, 2014 at 09:44 PM 0
Share

Hard to say without seeing what you ended up with, but my guess would be that you didn't include this part in the header:

 : $$anonymous$$onoBehaviour
avatar image Bunny83 getyour411 · Apr 26, 2014 at 09:51 AM 0
Share

That's not possible ;) If the class isn't derived from $$anonymous$$onoBehaviour / Component it can't be attached to a GameObject at all.

avatar image getyour411 getyour411 · Apr 26, 2014 at 03:11 PM 0
Share

oi, true dat

edit: changed to comment

avatar image dingben · Jul 04, 2015 at 02:33 AM 0
Share

Correct me if I am wrong, but script will not receive the onDestroy event unless one of the mentioned methods is in the script to begin with, thus [for example] adding a Start(){//do nothing} in the script may be what is needed.

avatar image AnneSchmidt_legacy · Jun 17, 2016 at 08:04 AM 1
Share

@Bunny83: The same thing happened to me as well. Thanks for the explanation! :)

avatar image Estecka · Mar 28, 2017 at 10:03 PM 2
Share

Even with the checkbox invisible, is it however still possible to "disable" and "enable" the component through scripting, then force said component to shutdown with statement like if(isActiveAndEnabled) ? Would this be good practice ?

avatar image Eluem Estecka · Mar 03, 2019 at 04:41 PM 0
Share

Seems like good practice to me, if that's something you need to be able to do.

Also, to answer the question about whether or not OnTriggerEnter2D, for example, will still run even if the Behavior is disabled, it will.

I was encountering this issue and I was confused. I disabled my behaviors that had triggers in them and they continued to go off. Threw me through a loop for a $$anonymous$$ute lol

Bunny83's answer actually helped me realize why. I also have a behavior that's for handling OnDestroy and it didn't have a disable check box. I was wondering why that was and this helped me realize why disabling my script wasn't working.

avatar image Titant3 · Jun 19, 2017 at 06:16 AM 1
Share

Thank you ! great answer.

Show more comments
avatar image
2

Answer by eovento · Apr 08, 2019 at 09:51 AM

I had the same issue: the checkbox suddenly disappeared from my script. In my case, it was not about inheriting or not from Monobehaviour (it was), the problem seems to reside on presence (or not) of a Start function. I was using Awake and removed Start method. If I create Start again, even if leaving it empty, the checkbox reappears on Inspector.

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

28 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

Related Questions

Exposing Variable and Enforce Component Dependencies. 1 Answer

How to "Collapse all" components on gameobject in inspector window? 0 Answers

Extend default image script to add feature? 0 Answers

Public script references in the Inspector 2 Answers

Certain components do not update in-game until refreshed in inspector 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