Can't disable some components in inspector

Noticed that some scripts can’t be disabled in inspector. Like this PlayerAttack one

Why this happens? I wanted so start them all disabled and enable manually to make ensure that everything is loaded in right order without creating some additional methods and properties.

1 Like

Only scripts implementing certain methods (such as Start() but there are others) will have that checkbox.

I forget the exact list but it’s findable in the documentation.

2 Likes

Just like Kurt said there is Start, Awake, Update, OnEnable OnDisable. If you don’t use any of the methods which react to enable state then there is no point in Unity showing UI to change it. In theory you can reuse the enable property for other stuff, but the main usecase is still the methods mentioned before.

1 Like

For future reference, using Unity 2022.2.5f1 I just went through all the accessible built-in methods listed here: Unity - Manual: Order of execution for event functions.

Methods that caused the enable-component checkbox to appear in the Unity Editor:

  • OnEnable, Start, FixedUpdate, Update, LateUpdate, OnGUI, OnDisable

Methods that did NOT cause the enable-component checkbox to appear in the Unity Editor:

  • Awake, Reset, OnAnimatorMove, OnAnimatorIK, OnTriggerEnter, OnCollisionEnter, OnMouseEnter, OnPreCull, OnWillRenderObject, OnBecameVisible, OnBecameInvisible, OnPreRender, OnRenderObject, OnPostRender, OnRenderImage, OnDrawGizmos, OnApplicationPause, OnApplicationQuit, OnDestroy

I assume all the OnTrigger, OnCollision, and OnMouse methods would produce the same results.

Adding a “void Start() { } // Do nothing.” line brings the enable checkbox back, if I ever need that. Any of the above group of seven methods above should work, but Start may have lower overhead than one of the update methods.

I was unable to find any documentation about this. But I did find some other methods that activated the enable-component checkbox and that Start line trick here: Cannot enabled / disable a script component?

Thank you to the people who answered earlier. You helped me figure this out quickly!

2 Likes