Global triggers

App-wide events you can raise from anywhere in your code.

Some events don't belong to any screen: the connection drops, an achievement unlocks, a push message arrives. Global triggers are ports that stay live whatever state is showing, and any code can fire them without a reference to the state machine.

Declaring global triggers

Derive from GlobalTriggers<TSelf>, declare Trigger events as usual, and add a static method per event that calls Raise:

GameEvents.cs
using StateFlow.Runtime.Components.Global;
using StateFlow.Runtime.Delegates;

public class GameEvents : GlobalTriggers<GameEvents>
{
    public event Trigger ConnectionLost;
    public event Trigger<string> AchievementUnlocked;
    public event Trigger<string> MessageReceived;

    public static void RaiseConnectionLost() => Raise(events => events.ConnectionLost);

    public static void RaiseAchievementUnlocked(string title) => Raise(events => events.AchievementUnlocked, title);

    public static void RaiseMessageReceived(string message) => Raise(events => events.MessageReceived, message);
}

Raise has overloads for Trigger, Trigger<T> and Trigger<T1, T2>. The selector runs inside your class, the only place its events can be read.

Adding the node

Right-click the graph and choose Create › Global Triggers, name it and drag in the script. Wire its ports to states or toasts like any other trigger.

StateFlow Editor — Toasts and Global Triggers
A green Game Events node with ConnectionLost, AchievementUnlocked&lt;String&gt; and MessageReceived&lt;String&gt; ports, wired to a No Connection alert, an Achievement Toast and a Message Toast, inside an 'Always on' group.
Game Events is wired to an alert and two toasts. Grouping app-wide nodes keeps them easy to find.

Raising them

Call the static method from anywhere: a network service, an achievements system, a debug menu.

NetworkMonitor.cs
private void OnDisconnected()
{
    GameEvents.RaiseConnectionLost();
}
Play mode
A Connection lost alert open over the Home screen, with a side panel of buttons that raise global triggers.
Raised from a button outside the StateFlow hierarchy that knows nothing about states.

How they behave

Try it

Import Feature Samples from the Package Manager and open 08 Toasts and Global Triggers/08 Toasts and Global Triggers.unity. About the samples