Search Unity

component on/off checkbox not showing up in the inspector

Discussion in 'Scripting' started by arioch82, Aug 10, 2010.

  1. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    Hi all,

    I've got an odd problem, basically the checkbox in the inspector to enable/disable the component is not showing up for some of my scripts.

    I've a base c# class defined (inside the plugin folder) like this:

    public class MyClassBase : MonoBehaviour{
    }

    then from here I define new classes with inheritance

    in c#:

    public class MyClassDerived : MyClassBase{
    }

    or javascript:

    class MyClassDerived extends MyClassBase{
    }

    well everything is fine and the checkbox appear for the js script but it doesn't for the c# script.

    do I have to use some special keyword on the class declaration?

    Thank you
     
  2. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    This is likely to do with all of Javas implicit background items.

    If an object does not have an Update(fixedUpdate as well) or Start function it will not be enableable or disableable. This is because there is no use to being able to disable something that doesn't update. You can still call functions on a disabled Monobehaviour and disabling just prevents the initial Start call and disables updating for that object.

    If you add an Update function it should become enableable.
     
    kingzora5 and freakybr like this.
  3. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    thank you first of all.

    my "derived class" implements a specialization of a coroutine and I'd love to enable/disable coroutines execution in the editor simply by turning off the component.

    Adding an empty void Start(){} does the trick but I'm wondering if there's any special keyword to put somewhere (something like [System please_show_the_disable_checkbox]) to force it and save all the fake calls on Start.

    Do you know if anything like this is available?
    thanks again
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    There is no such attribute to set.

    putting in a fake start does the trick there though.

    Guess the reasoning is that a component that is never actively used ( start, update, ongui), it also does not do any active job and thus does not need to be disabled.

    its important that a lot of things on monobehaviours are not touched at all by disabling it, its those 3 functions I mentioned above that are primarily touched by disable
     
    trancesilken and SpencerGreller like this.
  5. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    ok just wondering because if you try to start a coroutine on a disabled script/component (or disable the script after starting the coroutine) it simply won't start (/will stop) so in that case enable/disable has a meaning also if the component itself doesn't start/update/ongui anything.

    Thank you to both of you anyway, this community is just great as always :)
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Indeed, with coroutines it likely has to do with the fact that the "coroutine schedule" checks for yield in the global update round and only checks active behaviors

    thats also the reason why coroutines are affected by timeScale (at least from what I recall, they are), cause timeScale affects Update
     
  7. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    To be sure...FixedUpdate and LateUpdate are also affected, right ?
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    yes and yes :)
     
  9. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    Is there still no way to get this checkbox without adding an Update function? I'd love to use the script enabled state to use it in my own logic, but without needing to add an Update function. I know I could add a bool variable to do this and check it in update, but it's not so.. nice.
     
  10. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    You should still be able to set enabled to true or false through code, even if there is no checkbox in the inspector.
     
  11. Skokon

    Skokon

    Joined:
    Jul 23, 2017
    Posts:
    74
    My solution is that i declare a start void then disable the component and then remove the void