FGantryMessageRouter
The C++ message bus behind UGantryMessageSubsystem: delivers any struct on gameplay-tag channels to whoever listens, with no reference between sender and listener.
Most code uses UGantryMessageSubsystem, which holds one router per game instance. Use a router directly when you want a private bus of your own, for example inside one system or in a test.
A listener names:
- a channel;
- the struct it expects, or none to take any;
- how it matches channels: Exact, or Partial for the channel and every channel under it;
- optionally an owner. Once the owner is gone, the listener is dropped at the next message.
A message whose struct is not the listener's (or a child of it) is not delivered to that listener, and a warning in the log says so.
Delivery is immediate: listeners on the exact channel first, in registration order, then Partial listeners on each channel above it. While being called, a listener may add or remove listeners, itself included, and send further messages. A router has no lock: use each one from a single thread.
Hooks
A hook is a channel whose listeners can change what happens. RunHook hands every hook listener the payload itself (not a copy), highest priority first (registration order breaks ties, Partial listeners on channels above included), each able to change it, mark it handled, or cancel it, which stops the rest. The caller reads the payload back and acts on the result. A hook nobody listens to costs a map lookup per tag level, so games can place them freely.
Members
FCallback
using FGantryMessageRouter::FCallback = TFunction<void>
What a listener is called with: the channel the message was sent on, its struct, and the message.
FHookCallback
using FGantryMessageRouter::FHookCallback = TFunction<void>
What a hook listener is called with.
Register
int32
Adds a listener.
Channel:The channel to listen on.
Type:The struct expected; null takes any.
Match:Exact, or the channel and every channel under it.
Owner:When set, the listener lasts only as long as this object.
Callback:Called for each message delivered.
Returns: The listener's id, never 0.
Unregister
void
Removes a listener by the channel and id Register gave.
Unknown ids do nothing.
Broadcast
int32
Sends a message to everyone listening on Channel, then to Partial listeners on each channel above it.
Channel:The channel.
Type:The message's struct.
Payload:The message.
Returns: How many listeners it was delivered to.
Num
int32
Returns: How many message listeners are registered, owners not yet checked. Hook listeners are not counted.
Reset
void
Removes every listener and hook listener.
RegisterHook
int32
Adds a hook listener.
Channel:The hook.
Type:The struct expected; null takes any.
Match:Exact, or the hook and every hook under it.
Priority:Higher runs first.
Owner:When set, the listener lasts only as long as this object.
Callback:Called each time the hook runs.
Returns: The listener's id, never 0.
UnregisterHook
void
Removes a hook listener by the channel and id RegisterHook gave.
RunHook
FGantryHookResult
Runs a hook: every listener on Channel and Partial listeners on the channels above it, highest priority first, until one cancels.
Channel:The hook.
Type:The payload's struct.
Payload:The payload, changed in place by the listeners.
Returns: How many listeners ran, and whether one handled or cancelled it.
HasHookListeners
bool
Returns: Whether anything listens for Channel (or, Partially, a channel above it).