Awake being executed even if script is disabled

The Awake() function seems to be called even if the script is disabled (but the game object enabled).

I’ve experienced this and just wanted to share and confirm if anyone saw this as well, and if it’s working as intended.

I didn’t find this information in the docs, but I was having some strange behavior because of that, until I figured this out.

What it means for a script to be disabled isn’t terribly well documented.

AFAIK, Awake and Start are always executed no matter whether the script is enabled or disabled. Also, any functions you define that are not event handlers are accessible and can be called from other scripts whether the script is enabled or not.

What ARE enabled/disabled are Update, LateUpdate, OnGUI, and any other event handler that is ordinarily executed every frame.

So enabling a script does not make it as if it doesn’t exist, it just means that it’s not running its event loops. This is actually a good thing, since you can turn scripts off and on to increase performance, but still have them initialize and have their functions accessible.

I’m pretty sure Start is affected by enable/disable. I think it’s in the documentation somewhere, but it’s not easy to find. I have a lot of Awake functions I renamed to Start just so I could turn off the initialization behavior.

That’s good to know!

Yes awake is called for all components when an Object is Initialised, so when the level is loaded or when the object is created/Instantiated regardless of the status of any component.
Use Start().

Check unifycommunity.com for a list of calls in order.

The documentation on Start() is pretty clear about this, too: Unity - Scripting API: MonoBehaviour.Start()

Start will be called when the object becomes active before any Update calls.

Good to know!

Thanks for the info. I had no idea.