Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why do some Components have enable/disable checkboxes in the Inspector while others don't?

Discussion in 'Editor & General Support' started by majeric, Mar 10, 2016.

  1. majeric

    majeric

    Joined:
    Aug 17, 2010
    Posts:
    89
    Shouldn't all and ever component have a check box where you could disable it?
     
    AntonioModer likes this.
  2. MarimoAli

    MarimoAli

    Joined:
    Jan 16, 2015
    Posts:
    18
    I might be wrong, but if you don't have void Start(), in a script, it won't have the check box you are referring to :).


    -Ali
     
    BeefyMcWhatnow likes this.
  3. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    369
    Almost...It's if if doesn't have OnEnable()..in the script
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    A MonoBehaviour has a checkbox if it has any methods that care about the enabled property. These are, afaik:

    Start
    Update
    FixedUpdate
    LateUpdate
    OnEnable
    OnDisable


    Of note, Awake, all of the physics methods (OnTriggerX, OnCollisionX), and all of the mouse methods (OnMouseEnter, Down, Drag, Exit, Over, etc.) will not create the checkbox. This is because they don't care if the script is disabled, and will still get called.

    It is completely counter-intuitive and really bad design that a disabled script will receive OnTriggerEnter, but that's a discussion for another day.

    EDIT: the .enabled property isn't defined on Component, but on several subclasses of Component - like Behaviour and Collider. So there's a lot of Components you can't disable, like Rigidbodies and Joints. Why you can't disable them is probably because it was deemed as not useful or meaningful to disable those components.