Performance: Awake vs Start execution order
This concept affects the initialization timing of game objects, impacting frame load time and responsiveness during scene startup.
void Awake() {
// Lightweight setup
InitializeBasicStuff();
}
void Start() {
// Setup that depends on other objects
InitializeHeavyStuff();
}void Start() {
// Heavy setup that depends on other objects
InitializeHeavyStuff();
}
void Awake() {
// Empty or minimal
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy initialization in Start | N/A | Blocks main thread | Delays first frame paint | [X] Bad |
| Lightweight Awake + deferred Start | N/A | Minimal blocking | Smooth first frame paint | [OK] Good |
Awake or Start?Awake first to initialize objects early.Start timingStart runs after Awake, before gameplay begins.Awake is called before Start. -> Option AAwake method in a Unity C# script?Awake automatically if defined as void Awake().Awake is usually private by default, so void Awake() is correct and common.void Awake() { } -> Option Cvoid Awake() syntax [OK]void Awake() { Debug.Log("Awake called"); }
void Start() { Debug.Log("Start called"); }Awake first, so "Awake called" logs first.Start runs after AwakeStart runs, logging "Start called" second.Start never runs:void Awake() { Debug.Log("Awake"); }
void start() { Debug.Log("Start"); }Start must be capitalized.start is ignored, so Start never runs.start method name is lowercase, should be Start. -> Option BScript A:
void Awake() { Debug.Log("A Awake"); }
void Start() { Debug.Log("A Start"); }
Script B:
void Awake() { Debug.Log("B Awake"); }
void Start() { Debug.Log("B Start"); }
Awake methods before any Start methods.Awake calls, Unity calls all Start methods.Pass the test and this pattern moves unknown