BomberUnits
...a Unity learning project
How to startup Behaviours

How to startup Behaviours

Unity provides a two-step approach to the startup phase of a script:

During startup, the Awake() Callback is called once the script is activated. This is done before any Start() Callbacks are called on them. During awake, no assumptions can be made on the state of other behaviours, whose objects are created in the same frame. (Objects of which you know have been created way before will of course be in a stable state.)

The Awake()should thus be used to initialize things internal to the script. As you have no control over the instantiation. Awake() will also be called when the GameObject the script is attached to becomes active. Do things such as:

  • Check whether options were set correctly and prefabs have been assigned.
  • Assign singleton instance pointers if your script follows this pattern.
  • Access code you know is initialized, such as reading settings.

The Start() Callbacks are called after all awakes are done. Use this to, for example, collect references to other scripts.