Tier 3
Series 200
200D: The Flight Computer
"You can't have two captains flying one plane. If you reload a level and create a second Game Manager, they will fight for control of the score. A skilled Architect audits for Instance Uniqueness."
The Concept: The Singleton Pattern
A **Singleton** is a script that ensures only ONE copy of itself exists in the universe. It acts as the central Flight Computer.
* **Static Instance:** Allows any script to access `GameManager.Instance` from anywhere.
* **Duplicate Check:** If a second computer turns on, it must immediately shut down to prevent conflicts.
* **Static Instance:** Allows any script to access `GameManager.Instance` from anywhere.
* **Duplicate Check:** If a second computer turns on, it must immediately shut down to prevent conflicts.
Red Flag Detected
The AI Trap: "The Duplicate Captain"
You ask the AI: "Create a GameManager to track the global score."
// AI-Generated Code: The "Zombie" Singleton
public static GameManager Instance;
void Awake() {
Instance = this;
DontDestroyOnLoad(gameObject);
// Audit Fail: If you reload the scene, a 2nd Manager creates itself.
// Now you have two scores updating at once!
}
This is "Instance Collision." You will see bugs where the score adds up twice as fast, or music plays over itself.
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 Architect's Correction
Corrective Protocol
// Corrected: The "Highlander" Rule (There can be only one)
void Awake() {
if (Instance == null) {
Instance = this;
DontDestroyOnLoad(gameObject);
} else {
Destroy(gameObject); // Self-destruct the duplicate
}
}
Your Pilot Command
> A skilled Architect directs the AI to Seal the Cockpit. You command: "Implement the Singleton pattern with a duplicate check to destroy imposters."