Tier 4 Series 302

302F: The Event Bus

Pilot Record
Student Profile
"In a large fleet, if the Flagship has to manually call the radio of every fighter jet to say "Attack," the code becomes a spiderweb. An Event Bus allows the Flagship to shout "Attack" once, and anyone tuned to that channel reacts."

The Concept: The Event Bus Pattern

An **Event Bus** is a central highway for messages. Publishers send messages, Subscribers listen.

* **Decoupling:** The Sender doesn't know who is listening. The Listener doesn't know who sent it.
* **Channels:** Specific event types (`PlayerDiedEvent`, `LevelStartEvent`).
Red Flag Detected

The AI Trap: "The Reference Web"

You ask the AI: "Update the UI, play a sound, and spawn particles when the enemy dies."

// AI-Generated Code: Spaghetti References
public class Enemy : MonoBehaviour {
    public UIManager ui;     // Dependency
    public AudioManager aud; // Dependency
    public VFXManager vfx;   // Dependency
    
    void Die() {
        ui.UpdateScore();
        aud.PlayBoom();
        vfx.SpawnFire();
    }
}

This is "Coupling Overload." The Enemy script is now bloated with references to systems it shouldn't care about.

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 Navigator's Correction

Corrective Protocol
// Corrected: Fire and Forget
void Die() {
    // The Enemy just shouts into the void.
    EventBus.Publish(new EnemyDeathEvent(this.scoreValue));
}
// The UI listens elsewhere: EventBus.Subscribe<EnemyDeathEvent>(OnScore);
Your Pilot Command
> A skilled Navigator directs the AI to use an Event Bus.
Next Mission
The Architect's Exam