Skip to content

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 → BindUObjectue5-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

PropertyTypeCategoryNotes
URLFString (EditAnywhere, BlueprintReadWrite)BridgeReact app URL. If empty, falls back to Project Settings → Unreal React Bridge → Default Dev URL.
BridgeNameFString (EditAnywhere, BlueprintReadWrite)BridgeOptional name used by Subsystem::SendEvent(BridgeName, ...) to address this widget. Empty (default) = participates in BroadcastEvent only. Case-sensitive.
InitialStateTMap<FString, FString> (EditAnywhere, BlueprintReadWrite)Bridge | Initial StateEach 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

FunctionSignatureNotes
SendEventvoid SendEvent(const FString& EventName, const FString& JsonData)Queues if React not yet ready; queue is flushed once on OnReactReady.
LoadURLvoid LoadURL(const FString& NewURL)Resets bridge state (bIsReactReady = false, clears pending queue) and re-initializes on OnLoadCompleted.
IsReadybool IsReady() const (BlueprintPure)Has React called window.ue.bridge.ready() (i.e. fired onreactready) yet?

SendEvent

cpp
void SendEvent(const FString& EventName, const FString& JsonData);
ParamTypeRequiredNotes
EventNameFStringyesCase-sensitive
JsonDataFStringyesValid JSON string; reaches React as event.detail

Returnsvoid. Fires synchronously if ready; otherwise enqueued and flushed when OnReactReady is invoked.

LoadURL

cpp
void LoadURL(const FString& NewURL);
ParamTypeRequiredNotes
NewURLFStringyesNew page URL (http://, https://, or file:///)

Returnsvoid. Triggers the full lifecycle again: page load → bridge re-bind → OnReactReady re-fires.

IsReady

cpp
bool IsReady() const;

Returnstrue 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.

DelegateSignatureWhen
OnReactReadyEventFOnHUDReactReady()React signaled ready, bridge live, queued events flushed
OnEventReceivedFOnHUDEventReceived(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.
OnBridgeErrorFOnHUDBridgeError(const FBridgeErrorInfo& ErrorInfo)Any bridge error — see /reference/types#fbridgeerrorinfo
cpp
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 UUnrealReactBridgeSubsystem in NativeConstruct and unregisters in NativeDestruct — you don't call any registration API yourself.
  • LoadURL restarts the full lifecycle: page reload → bridge re-bind → OnReactReadyEvent fires again. Any state held in React is lost; rehydrate via InitialState on the next ready.
  • NativeOnFocusReceived is overridden to forward keyboard focus down to the embedded SWebBrowser, 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

text
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"  → 7
text
Level Blueprint
  Event BeginPlay
    └─ Create Widget (Class: WBP_MyHUD)  → HudRef
    └─ Add to Viewport (Target: HudRef)
cpp
// 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

Released under the MIT License.