Tier 1 Series 2

2F: Static Utilities

Pilot Record
Student Profile
"Imagine a pilot checking the fuel gauge. Every plane in the fleet has its own individual gauge (Instance). Now imagine the Air Traffic Control frequency. There is only one frequency for everyone in the sector (Static).

If you accidentally make a "Fuel Gauge" static, every plane in your game will share the exact same fuel tank. If one runs out, they all fall from the sky."

The Concept: Global vs. Local

We audit the "Static" keyword and its impact on memory.

Instance: Unique to one object. Deleted when the object is destroyed.
Static: Shared by all objects. Lives for the entire duration of the game.
Static Methods: Great for math utilities that don't need state.
Red Flag Detected

The Audit: Spot the "Global Leak" Error

You ask the AI: "Create an enemy script where I can easily see the health of any enemy from my UI manager."

// AI-Generated Code (Logic Failure)
public class Enemy : MonoBehaviour {
    public static int health = 100; // ERROR: Shared across ALL enemies!

    public void TakeDamage(int amount) {
        health -= amount;
    }
}

By making health static, you have created one health bar for the entire army. If you hit "Enemy A," "Enemy B" and "Enemy C" also lose health.

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
// Corrected Code (Proper Isolation)
public class Enemy : MonoBehaviour {
    public int health = 100; // Unique to each enemy instance
}

// Static is reserved for logic that never changes
public static class CombatMath {
    public static int CalculateCrit(int damage) => damage * 2;
}
Your Pilot Command
> Implement an Object Pool to manage active and inactive instances.
Next Mission
The Logic Exam