- Home /
No enable/disable check box for a script?
After adding a particular script to a GameObject, I notice that there's no little check box to enable/disable it in the inspector. Would anyone know why this is?
I see that things like Transforms and Mesh Filters don't have that check box either, but I can understand that--they're more low-level sorts of things. I just found it bizarre that a script could be missing this option too.
(Hint: this is happening on one of the NGUI example scripts, if that helps.)
Answer by Eric5h5 · Aug 09, 2012 at 04:50 AM
Disabling a script only turns off Update (plus related such as FixedUpdate) and OnGUI, so if those functions aren't present then disabling a script isn't possible.
And also Start
.
Note that a script which does not contains any of these methods will not receive the OnDestroy
event. Therefore it is sometimes required to have an empty Start
method.
You don`t need to have a Start method to receive the OnDestroy event in Unity 2018.4.13f1 (64-bit)
Answer by Cascho01 · Sep 08, 2015 at 09:09 AM
My script had a "OnMouseDown()" only. I also wanted to disable the script (for test reasons). What I did is this:
Add
void Update(){
}
and
void OnMouseDown(){
if(enabled)
do();
}
Answer by ataraxia · Nov 29, 2016 at 08:16 AM
Having only Start() also enables the on/off checker box from inspector. This means turned off script doesn't process Start(), either.
This is true (unlike Awake() ), and better than using Update() since it won't cause overhead.
Your answer
