UWebHUDWidget
Source: SampleProject/Plugins/UnrealReactBridge/Source/UnrealReactBridge/Public/WebHUDWidget.h
UUserWidget subclass that hosts an embedded UBindableWebBrowser and manages the full bridge lifecycle (CEF load → BindUObject → ue5-bridge-ready → event queue flush). Create a Widget Blueprint child of this class for the widget-first authoring path.
- UCLASS:
Abstract,BlueprintType - Display name: Web HUD Widget Base
- Parent path (BP):
UMG → User Widget → Web HUD Widget Base
Required Designer wiring
Inside your WBP, place a Bindable Web Browser widget and name it WebBrowser exactly (case-sensitive BindWidgetOptional lookup). The base class binds window.ue.bridge to that widget after OnLoadCompleted. If the binding fails, you'll see an OnBridgeError with EBridgeErrorType::WebBrowserNull.
Properties
| Property | Type | Category | Notes |
|---|---|---|---|
URL | FString (EditAnywhere, BlueprintReadWrite) | Bridge | React app URL. If empty, falls back to Project Settings → Unreal React Bridge → Default Dev URL. |
BridgeName | FString (EditAnywhere, BlueprintReadWrite) | Bridge | Optional name used by Subsystem::SendEvent(BridgeName, ...) to address this widget. Empty (default) = participates in BroadcastEvent only. Case-sensitive. |
InitialState | TMap<FString, FString> (EditAnywhere, BlueprintReadWrite) | Bridge | Initial State | Each value is treated as a JSON literal (object, array, number, string, bool, null). Values that fail to parse are wrapped as JSON strings. Delivered to React as ue5-bridge-ready.detail.initialState[key]. See /guide/initial-state. |
Functions
| Function | Signature | Notes |
|---|---|---|
SendEvent | void SendEvent(const FString& EventName, const FString& JsonData) | Queues if React not yet ready; queue is flushed once on OnReactReady. |
LoadURL | void LoadURL(const FString& NewURL) | Resets bridge state (bIsReactReady = false, clears pending queue) and re-initializes on OnLoadCompleted. |
IsReady | bool IsReady() const (BlueprintPure) | Has React called window.ue.bridge.ready() (i.e. fired onreactready) yet? |
SendEvent
void SendEvent(const FString& EventName, const FString& JsonData);| Param | Type | Required | Notes |
|---|---|---|---|
EventName | FString | yes | Case-sensitive |
JsonData | FString | yes | Valid JSON string; reaches React as event.detail |
Returns — void. Fires synchronously if ready; otherwise enqueued and flushed when OnReactReady is invoked.
LoadURL
void LoadURL(const FString& NewURL);| Param | Type | Required | Notes |
|---|---|---|---|
NewURL | FString | yes | New page URL (http://, https://, or file:///) |
Returns — void. Triggers the full lifecycle again: page load → bridge re-bind → OnReactReady re-fires.
IsReady
bool IsReady() const;Returns — true once React has called window.ue.bridge.ready() and the queued events have been flushed.
Delegates
All delegates are BlueprintAssignable and live under category Bridge.
| Delegate | Signature | When |
|---|---|---|
OnReactReadyEvent | FOnHUDReactReady() | React signaled ready, bridge live, queued events flushed |
OnEventReceived | FOnHUDEventReceived(const FString& EventName, const FString& JsonData) | A React-side event arrived. Receiver components handle most cases; this delegate is for ad-hoc handling directly on the widget. |
OnBridgeError | FOnHUDBridgeError(const FBridgeErrorInfo& ErrorInfo) | Any bridge error — see /reference/types#fbridgeerrorinfo |
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnHUDReactReady);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnHUDEventReceived,
const FString&, EventName,
const FString&, JsonData);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnHUDBridgeError,
const FBridgeErrorInfo&, ErrorInfo);Lifecycle notes
- The widget self-registers with
UUnrealReactBridgeSubsysteminNativeConstructand unregisters inNativeDestruct— you don't call any registration API yourself. LoadURLrestarts the full lifecycle: page reload → bridge re-bind →OnReactReadyEventfires again. Any state held in React is lost; rehydrate viaInitialStateon the next ready.NativeOnFocusReceivedis overridden to forward keyboard focus down to the embeddedSWebBrowser, since UMG container widgets don't normally pass focus to CEF.- The C++ class is
Abstract— you cannot place it in the viewport directly; always subclass via a Widget Blueprint.
Example
WBP_MyHUD (parent: Web HUD Widget Base)
└── WebBrowser ← Bindable Web Browser widget (name MUST be "WebBrowser")
Class Defaults
URL: http://localhost:5173
BridgeName: MainHUD
InitialState:
"player" → {"name":"Alice","hp":100}
"level" → 7Level Blueprint
Event BeginPlay
└─ Create Widget (Class: WBP_MyHUD) → HudRef
└─ Add to Viewport (Target: HudRef)// C++: drive the widget after creation
if (UWebHUDWidget* Hud = CreateWidget<UWebHUDWidget>(GetWorld(), MyHudClass))
{
Hud->InitialState.Add(TEXT("player"),
TEXT("{\"name\":\"Alice\",\"hp\":100}"));
Hud->AddToViewport();
Hud->OnReactReadyEvent.AddDynamic(this, &AGameMode::HandleReactReady);
Hud->OnEventReceived.AddDynamic(this, &AGameMode::HandleHudEvent);
}See also
/guide/first-hud— build your first widget-first HUD/guide/initial-state— howInitialStateserializes and lands on the JS side/guide/lifecycle— full load → ready → destruct timeline/reference/types—FBridgeErrorInfo,EBridgeErrorType