Skip to content

Blueprint view models

A view model can be a Blueprint: no C++ is needed for the data, the functions a document calls, or the Blueprint that opens the document. The BlueprintViewModel sample (see Samples) is a counter built this way. What still needs C++ is a resolver and FArcRmlStructList rows (Data binding).

Create a view model Blueprint

  1. In the Content Browser choose Add > Blueprint Class. In the Pick Parent Class window open All Classes, search for MVVMViewModelBase and pick it. Name the asset, for example BP_MyVM.
  2. Add a variable for each value the document shows. In the variable's Details, turn Field Notify on.
  3. Add a function for each action the document calls, and set the variable inside it with the Set node of the Field Notify variable (SET w/ Broadcast).
  4. Compile and save. The class the document names is the asset path, a dot, and the asset name followed by _C. The asset Content/UI/BP_MyVM of the project has the asset path /Game/UI/BP_MyVM, so its class is /Game/UI/BP_MyVM.BP_MyVM_C; use it as the class of the <viewmodel> declaration. In a plugin the first part is the plugin's name, as in the sample below.

The sample below follows these steps.

The view model

BP_SampleVM is a Blueprint whose parent class is MVVMViewModelBase. It has three variables with Field Notify on:

Variable Type Default
Title String Blueprint view model
Count Integer 0
Step Integer 2

Only Field Notify variables can be read from a document. A document updates only when the view model broadcasts the field: the Set node of a Field Notify variable does that (the node is titled SET w/ Broadcast).

The function Increment has no parameters. Build it in four nodes:

  1. Drag Count from the My Blueprint panel into the graph and choose Get.
  2. Do the same for Step.
  3. Add an integer add node (+) and connect Count and Step to its two inputs.
  4. Drag Count in again and choose Set; the node is titled SET w/ Broadcast. Connect the sum to its Count input, and the function's entry node to its execution input.

The document

BlueprintViewModel.rml
<viewmodel name="counter" class="/ArcRmlUISamples/UI/Rml/BlueprintViewModel/BP_SampleVM.BP_SampleVM_C" create="true"/>

A Blueprint view model is named by its generated class: the asset path, a dot, and the asset name followed by _C. create="true" makes a new instance when the document opens. The rest of the document reads the fields and calls the function like any other view model:

BlueprintViewModel.rml
<body :model="counter">
    <div class="bv-panel">
        <h1 class="bv-title">{{ counter.Title }}</h1>
        <p id="bv-count">Count: {{ counter.Count }}</p>
        <p>Step: {{ counter.Step }}</p>
        <div class="bv-buttons">
            <button id="bv-increment" class="bv-button" on:click="call('counter', 'Increment')">Add step</button>
            <button class="bv-button" data-action="close">Close</button>
        </div>
    </div>
</body>

call('counter', 'Increment') calls Increment on the model counter; "Add step" adds Step to Count. data-action="close" closes the document.

Which Blueprint functions a document can call

  • The function is a function of the view model Blueprint, not pure and not const. A custom event cannot be called.
  • The argument count in call(...) must match the function's input count exactly. Return values and output parameters are dropped.
  • There is no property write from RML: to change a field, call a function that sets it.
  • A call on a preview model only logs (see Editor preview).

The View models and Events pages cover call in full.

Opening the document from a Blueprint

BP_BlueprintViewModel_Open is a Blueprint Function Library. Its function Open has the input PlayerController and the output Document (an ArcRmlDocumentRef). The graph is:

  1. Make Arc Rml Document Ref with Path set to /ArcRmlUISamples/UI/Rml/BlueprintViewModel/BlueprintViewModel.rml.
  2. Get ArcRmlViewportSubsystem, from the PlayerController.
  3. Open Document on that subsystem with the made reference.
  4. Branch on the returned bool: when true, return the reference as Document.

The document needs nothing else, because it creates its own model. The Quick start shows the same open from C++.

Run it

Play in the map L_ArcRmlSamples and choose BlueprintViewModel in the Blueprint group of the samples list. The second way is the console:

ArcRmlSamples.OpenBP BlueprintViewModel

ArcRmlSamples.OpenBP calls the Open function of the sample's Blueprint Function Library. ArcRmlSamples.Close closes the document again.

You should see the title Blueprint view model, Count: 0 and Step: 2. Each press of Add step raises the count by 2.

Next

  • Documents: how a document opens and closes, and what its head declares.