In this lesson, you will learn how to trigger diverse, independent reactions across your game world using a single broadcast event.
The "One-To-Many" Concept
When you are building complex systems, you often encounter a scenario where one action—like a player leveling up—needs to trigger multiple unrelated systems: the UI needs to update, the sound manager needs to play a fanfare, and the particle system needs to spawn confetti.
If the "Level Up" script tries to find and talk to every one of those systems individually, your code becomes tightly coupled and brittle. Instead, we use One-To-Many Event Communication. By utilizing a ScriptableObject Event Channel, the "Level Up" script acts as a broadcaster that simply shouts, "The player leveled up!" It has no idea who is listening, and it doesn't care.
Practical Implementation
To set this up, your broadcaster doesn't hold references to the listeners. Instead, it references a shared ScriptableObject Event Channel. Any system that cares about this event simply "subscribes" to that channel during its initialization.
// Inside the Broadcaster (e.g., LevelManager)
public VoidEventChannel levelUpEvent;
public void CompleteLevel() {
levelUpEvent.Raise(); // One broadcast, zero knowledge of listeners
}
// Inside a Listener (e.g., UIManager)
public VoidEventChannel levelUpEvent;
private void OnEnable() => levelUpEvent.OnEventRaised += UpdateUI;
private void OnDisable() => levelUpEvent.OnEventRaised -= UpdateUI;
private void UpdateUI() { /* Logic to show level up text */ }
By decoupling the broadcaster from the listeners, you can add or remove reactions—like adding a new "Achievement System"—without ever touching the code that triggers the level-up. The broadcaster stays clean, while the new system simply registers itself to the channel. This architecture allows your disparate game systems to act as a cohesive whole without ever becoming physically linked in your project hierarchy.
Key Takeaway: Use a shared event channel to broadcast messages so that a single action can trigger an unlimited number of independent, decoupled systems simultaneously.