Skip to content

Core Concept: The Signal

A Signal is a broadcast-style event. It functions exactly like a C# event but with “Superpowers.”

  1. 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.
  2. 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.
// 1. Define Signals
public 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);
}