Skip to content

A document in a UMG widget

A Widget Blueprint can show a document with the document widget (UArcRmlDocumentWidget, palette category ArcRmlUI). The widget draws the document in its slot, next to your own UMG widgets, with no layer and no call to OpenDocument. The UmgWidget sample is a Widget Blueprint with a text block and this widget. Run it by choosing UmgWidget in the samples list in the map L_ArcRmlSamples (Samples).

The UmgWidget sample: a UMG text block above a card titled UMG widget that shows Count: 0 and the buttons Add one and Close

Add it to a Widget Blueprint

  1. Open the Widget Blueprint and switch to the Designer.
  2. In the Palette, open the category ArcRmlUI and drag Arc Rml Document Widget into the Hierarchy or onto the canvas, under the widget that should hold it.
  3. Select it and set Document in the Details panel to an .rml document.
  4. Size its slot. The document fills the widget's slot, so size the slot, not the document. A slot sized to its content (an Auto slot, a Canvas Panel Size To Content) gives the widget no size and the document does not show; use Fill or an explicit size.
  5. Compile the Widget Blueprint.

The UmgLayout sample puts the widget in a Size Box (Height Override 260) inside a Scroll Box, between text blocks. Its Designer, with the widget selected:

The Designer of WBP_Sample_UmgLayout. The Palette, filtered by ArcRml, lists Arc Rml Document Widget under the category ArcRmlUI. The Hierarchy shows a Canvas Panel holding a Scroll Box with two Text Blocks, a Size Box that holds the selected widget Document, and a Text Block. The Details panel shows the Document property under Arc Rml UI, Document Widget, set to a path under /ArcRmlUISamples/UI/Rml/

The document scrolls and clips with its neighbours:

The UmgLayout sample: two text blocks clipped at the right edge of the Scroll Box, above a card titled UMG layout; a scroll bar at the right

Set the document from code with SetDocument and reload it with ReloadDocument. In the Blueprint category ArcRmlUI|Document Widget:

Member What it does
Document The document to show. SetDocument loads another one; an empty path shows nothing.
SetViewModel Gives a manual model an object (below).
ReloadDocument Loads the same document again.
OnOpenRequested Fires with the path of a data-action="open:<path>" in the document.
OnCloseRequested Fires for a data-action="close" in the document.

Show the widget

A Widget Blueprint reaches the screen like any other: create it and add it to the player's screen. The samples do this in C++ with the two calls below; the Blueprint nodes Create Widget and Add to Player Screen are the same calls.

ArcRmlSamplesUmgEvents.cpp
UUserWidget* Widget = CreateWidget<UUserWidget>(Player, WidgetClass);
if (!Widget)
{
    return FArcRmlDocumentRef();
}
Widget->AddToPlayerScreen(ArcRmlSamplesUmgEventsPrivate::ZOrder);

ZOrder is 1500 in the samples, which puts the widget above the layer documents (below).

React to open and close

The widget opens and closes nothing itself. It fires OnOpenRequested and OnCloseRequested, and the Widget Blueprint decides what happens. The UmgEvents sample's document has two buttons:

UmgEvents.rml
<button id="ue-next" class="ue-button" data-action="open:/ArcRmlUISamples/UI/Rml/UmgEvents/Second.rml">Open the second document</button>
<button class="ue-button" data-action="close">Close</button>

Its event graph binds both requests in Event Construct with a Bind Event to On Open Requested and a Bind Event to On Close Requested node, each wired to a custom event. Dragging off the Document variable and choosing Assign On Open Requested creates such a pair in one step:

The event graph of WBP_Sample_UmgEvents. Event Construct runs Bind Event to On Open Requested and then Bind Event to On Close Requested; the Target of both is the Document variable. The custom event OnOpenRequested_Event has a Path output and sets Document on the Document widget to a Make Arc Rml Document Ref of that Path. The custom event OnCloseRequested_Event calls Remove from Parent on self

Open swaps the document and keeps the widget and its place on the screen; close removes the widget from its parent.

The UmgEvents sample: a text block above a card titled UMG events with the buttons Open the second document and Close

The two document actions need no :model on the document's <body>, so the sample declares no view model (Limits). A document action with no listener bound logs one LogArcRmlUI warning naming the widget, the document and the action.

Give it data

A manual model

The sample document declares one manual model, so the widget has none until game code sets it:

UmgWidget.rml
<viewmodel name="counter" class="/Script/ArcRmlUISamples.ArcRmlSamplesUmgWidgetViewModel" manual="true"/>

The sample's open function creates the widget, gives it the model and binds the close request:

ArcRmlSamplesUmgWidget.cpp
UUserWidget* Widget = CreateWidget<UUserWidget>(Player, WidgetClass);
UArcRmlDocumentWidget* Document = Widget ? Cast<UArcRmlDocumentWidget>(Widget->GetWidgetFromName(TEXT("Document"))) : nullptr;
if (!Document)
{
    return FArcRmlDocumentRef();
}

UArcRmlSamplesUmgWidgetViewModel* ViewModel = NewObject<UArcRmlSamplesUmgWidgetViewModel>(Widget);
ViewModel->Host = Widget;
Document->SetViewModel(TEXT("counter"), ViewModel);
Document->OnCloseRequested.AddDynamic(ViewModel, &UArcRmlSamplesUmgWidgetViewModel::HandleCloseRequested);
Widget->AddToPlayerScreen(ArcRmlSamplesUmgWidgetPrivate::ZOrder);

SetViewModel keeps the object per widget and applies it at each load. A name the document does not declare logs a warning.

A model the widget owns

create and context models need no call. A model with path= or resolver= reads from the widget the document sits in, so GetOwningPlayerPawn and the other getters of that widget are its roots (View models). The UmgOwnerData sample declares path="Stats", a property of its widget class, and sets nothing on the document:

UmgOwnerData.rml
<viewmodel name="stats" class="/Script/ArcRmlUISamples.ArcRmlSamplesUmgOwnerDataViewModel" path="Stats"/>

The UmgOwnerData sample: a text block above a card titled UMG owner data that shows Health: 40 and the buttons Heal and Close

What it does not do

  • No keyboard, gamepad or focus handling: the document answers the mouse only (Limits).
  • No frame or tabs; frame and every layer <meta> of the document's head are ignored.
  • No keep-alive and no size of its own: the document takes the slot's size.
  • Put the widget above the layer documents, as the samples do with a Z order of 1500: below a full-screen layer document it gets no pointer input (read from the code, not run).
  • A widget with no owning local player shows create and manual data and nothing else: path=, resolver= and context models stay empty and button calls are only logged. In a game that logs one warning at load.
  • Removing the widget from its parent does not close the document: it keeps its view, paused, until garbage collection, and its on-close does not run then. on-close runs when SetDocument loads another path, on ReloadDocument and when the widget's Slate resources are released while the widget lives.
  • Pausing: the document stops updating while the widget is not drawn and resumes when it is drawn again.