Tier 1 Series 1

1D: Efficiency Audit

Pilot Record
Student Profile
"Checking your oil is a Start procedure. You do it once before the flight. Checking your altitude is an Update procedure. You do it constantly while in the air. If a pilot tries to check the oil 60 times every second while flying, the plane will eventually fail due to the unnecessary 'drag' on the pilot's attention."

The Concept: Start() vs. Update()

As detailed in Chapter 2, Unity scripts follow a specific lifecycle. Knowing when an action happens is just as important as the action itself.

Start(): Runs once when the script begins. Perfect for "expensive" setup tasks like finding components.

Update(): Runs every frame (up to 60+ times per second). Used for movement and input.
Red Flag Detected

The AI Trap: "The Performance Drag"

You ask the AI: "Write a script that makes a game object change color when I press a key."

// AI-Generated Code: Creating major lag!
void Update() {
    // Audit Error: GetComponent is VERY expensive 
    // to run 60 times per second!
    GetComponent<Renderer>().material.color = Color.red;
}

The Sanity Error: GetComponent is like opening the hood of the car to check the engine. Doing this 60 times a second will cause your game's frame rate to "stutter" or drop, especially on mobile devices.

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 Command

Corrective Protocol
// Corrected Pilot Code: Smooth & Efficient
private Renderer myRenderer;

void Start() {
    // Check the "oil" once at the beginning
    myRenderer = GetComponent<Renderer>();
}

void Update() {
    // Use the stored reference for high-speed flight
    myRenderer.material.color = Color.red;
}
Your Pilot Command
> Direct the AI to use sqrMagnitude to avoid expensive square root calculations.
Next Mission
The Blueprint