View bindings (MVVM)
A Widget Blueprint that uses UE5's Model View ViewModel plugin has its view written between the class defaults and the functions, in up to six sections that are left out when empty: View models, View bindings, View events, View conditions, View settings and View extensions. A 4.27 widget has none of this.
View models
A view model line is its class, its name and how it is created: manual, new, global("Identifier"), path(Hero), resolver(BP_MyResolver) with the resolver's settings under it, context or instanced. Flags in brackets are the options that differ from the editor's default.
// ===== View models =====
VM_Player Hero = manual
VM_Player Hint = resolver(BP_HintResolver)
Category = Combat
VM_Player Player = new [CreateGetterFunction=False]
VM_Player Shared = global("PlayerShared") [Optional]
Bindings
A binding is widget <- view model when it writes the widget, -> when it writes the view model, and <-> both ways. A path is the widget's or view model's name, then the properties. Flags: OneTime, Execution=Tick (an execution mode override), and Enabled=False (compiled, but switched off until the widget switches it on). A conversion function stands in place of the path it converts, written as a call as in a graph.
Bindings are sorted by widget, with a blank line between widgets.
// ===== View bindings ===== HealthBar.Percent <- Player.Health [OneTime] NameInput.Text <-> Hero.Name KismetMathLibrary::FMin(A=VolumeSlider.MaxValue, B=100.0) -> Shared.Volume VolumeSlider.Value -> Shared.Volume [Enabled=False]
Events, conditions and the other sections
An event is on Widget.Event with the call it runs under it; a condition is when Path < 0.5, with in [a, b] for a range that includes its ends and in (a, b) for one that does not. A blank line sets each one apart. A binding, event or condition that is not compiled starts with [not compiled]: it does not exist at run time, as a [disabled] node in a graph. View settings list only the flags that were changed. A ListView extension names the entry widget and its view model, WBP_Entry.VM_Entry. The other sections are sorted by their first line.
// ===== View events =====
on FireButton.OnClicked
Player.Fire(5)
// ===== View conditions =====
when Player.Health < 10.0
PlayLowHealth()
[not compiled] when Player.Health in [10.0, 50.0]
PlayMidHealth()