Tier 2 Series 102

102D: The Execution Order Audit

Pilot Record
Student Profile
"You can't start the engine before you connect the battery. In Unity, scripts don't run in a guaranteed order unless you force them. If Script A tries to talk to Script B before Script B is ready, you get a 'Race Condition.' A skilled Engineer audits for Lifecycle Management."

The Concept: Awake vs. Start

Understanding the difference is critical for system stability.

* **Awake():** The 'Initialization' phase. Used to set up *internal* references (like GetComponent). Runs first.
* **Start():** The 'Communication' phase. Used to talk to *other* objects. Runs after all objects have Woken up.
Red Flag Detected

The AI Trap: "The Race Condition"

You ask the AI: "Set up the GameManager to find the Player."

// GameManager.cs
void Awake() {
    // Audit Fail: What if the Player hasn't run its Awake() yet?
    // You might get null, or partially initialized data.
    player = GameObject.Find("Player").GetComponent<Player>();
}

This is "Temporal Coupling." You are gambling that the Player loads before the Manager. If Unity decides to load them in reverse order today, your game crashes.

Elite Telemetry

Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."

  • Small Batches Solving one problem at a time prevents logic drift.
  • Modular Design Localizing the "blast radius" of AI changes.
  • Tight Loops Rapid iteration with constant code review.

The Pilot's Correction

Corrective Protocol
// GameManager.cs
void Start() {
    // Safe! We know all objects have finished Awake()
    player = GameObject.Find("Player").GetComponent<Player>();
}
Your Pilot Command
> Implement a Button click event using the RegisterCallback method.
Next Mission
Component Visibility Audit