Core Concept: The Signal
A Signal is a broadcast-style event. It functions exactly like a C# event but with “Superpowers.”
Key Guarantees
Section titled “Key Guarantees”- Guaranteed Delivery (Resilience):
If 10 systems are listening to OnPlayerDied and the 3rd one throws a NullReferenceException:
- Standard Event: Listeners 4 through 10 never hear the message. The game logic breaks.
- Signal: The error is logged, and listeners 4 through 10 are invoked immediately. Your game keeps running.
- Thread-Safe by Design:
Signals can be invoked from any thread (Job system, Network thread, async/await). If configured with
forceMainThread: true, the Signal automatically queues the execution to run safely on the next Unity Main Thread frame.
Code Example
Section titled “Code Example”// 1. Define Signalspublic Signal OnPlayerDied = new();public Signal<int> OnScoreChanged = new(forceMainThread: true); // UI Safe!
// 2. Subscribe (Identical to C# events)private void OnEnable(){ OnPlayerDied += HandleDeath; OnScoreChanged += UpdateScoreUI;}
// 3. Invoke (Safe & Fast)private void TakeDamage(){ // If this runs on a background thread, UpdateScoreUI will still work // perfectly because we set forceMainThread: true! OnScoreChanged.Invoke(currentScore);}