Skip to content

UUnrealReactBridgeSubsystem

Source: SampleProject/Plugins/UnrealReactBridge/Source/UnrealReactBridge/Public/UnrealReactBridgeSubsystem.h

UGameInstanceSubsystem that owns the HUD-widget registry and routes events between Sender/Receiver components and the active UWebHUDWidget instances. HUD widgets self-register in NativeConstruct and unregister in NativeDestruct, so most users never touch the subsystem directly — drop a ReactBridgeSender / ReactBridgeReceiver component and the wiring is automatic.

Use the subsystem directly when you need:

  • A targeted send from C++ without spawning a Sender component.
  • A targeted send from a Blueprint that doesn't have a Sender on hand (e.g. Game Mode, Subsystem, REST callback).
  • Diagnostics — manual broadcast during debugging.

TIP

Broadcasts that arrive before any HUD widget has registered are buffered (up to 100 entries) and flushed when the first widget registers. This means GameMode::BeginPlay initial-state pushes are safe even though the Level Blueprint creates the widget afterwards.

Get

cpp
static UUnrealReactBridgeSubsystem* Get(UWorld* World);

BlueprintCallable. Convenience accessor — resolves the owning UGameInstance from World and returns its subsystem, or nullptr if either is unavailable.

ParamTypeRequiredNotes
WorldUWorld*yesAny world reference (GetWorld(), WorldContextObject->GetWorld())

Returns — Subsystem pointer or nullptr.

BroadcastEvent

cpp
void BroadcastEvent(const FString& EventName, const FString& JsonData);

Fans the event out to every registered HUD widget in the current GameInstance.

ParamTypeRequiredNotes
EventNameFStringyesCase-sensitive event name. Matches React-side window.ue.bridge.on(name, ...) subscriptions.
JsonDataFStringyesValid JSON string. Pass "{}" for no payload. Reaches React as event.detail.

Returnsvoid.

Behavior — If no widget is registered yet, the broadcast is buffered (FIFO, capped at 100). The buffer drains the moment the first widget registers.

Example

cpp
if (auto* Sub = UUnrealReactBridgeSubsystem::Get(GetWorld()))
{
    Sub->BroadcastEvent(TEXT("game:paused"), TEXT("{\"reason\":\"menu\"}"));
}

SendEvent

cpp
void SendEvent(const FString& BridgeName, const FString& EventName, const FString& JsonData);

Targeted send — delivers only to the widget whose BridgeName matches.

ParamTypeRequiredNotes
BridgeNameFStringyesCase-sensitive. Must match UWebHUDWidget::BridgeName (or the Name of an Add Web HUD layer).
EventNameFStringyesCase-sensitive event name.
JsonDataFStringyesValid JSON string; "{}" for no payload.

Returnsvoid.

Behavior — Silently no-ops if BridgeName does not match any registered widget. If Debug Mode is enabled in Project Settings, the miss is reported in the Output Log. Targeted sends are not buffered: deliver-or-drop.

Example

cpp
if (auto* Sub = UUnrealReactBridgeSubsystem::Get(GetWorld()))
{
    Sub->SendEvent(TEXT("HpBar"), TEXT("player:health:update"),
                   TEXT("{\"value\":75,\"max\":100}"));
}

See also

Released under the MIT License.