Skip to content

UI and View Models

A game’s UI needs a great deal from the simulation: a unit’s health, what a selection can do, how many minerals the player holds, what a production queue is building. The simulation stores that data as fixed-point component structs keyed by entity handle, which is the wrong shape for a widget. View models are the layer between.

A view model is a read-only object that presents one piece of the simulation in a form a widget can use: text, textures, floats, arrays, tags and events. Reading through one cannot change the match. A button on the UI still acts the way a right-click does, by issuing an order or a command. See Presentation and Visual Events.

Make a widget a Sein User Widget and it can reach the view models without any setup. In the Content Browser, use Add > SeinARTS > View Model Widget (under User Interface), or set the parent class of a Widget Blueprint to Sein User Widget.

When the widget is constructed it finds the UI subsystem, the local Sein Player Controller and the world’s simulation, and holds them in variables. This happens before Event Construct, so those variables are valid there. It also adds accessors:

Node Returns
Get Selection Model The local player’s selection.
Get Local Player View Model The local player’s resources and tech.
Get Entity View Model The view model for one entity handle.
Get Minimap View Model The minimap’s blips and textures.
Get Actor Bridge The actor bridge subsystem, for visual events.

Consume Clicks is on by default. A Sein User Widget swallows left and right clicks that none of its controls handled, so a click on a panel does not select or order a unit behind it. For a full-screen HUD, set the root canvas panel’s Visibility to Not Hit-Testable (Self Only) and keep the panels you want clickable Visible. Empty screen then stays playable.

The UI subsystem refreshes every view model once after each rendered frame in which the simulation ran at least one tick. A frame that ran none does not refresh them. In practice you can read them freely from Event Tick or a binding: they hold the latest completed tick’s data. Their On Refreshed events fire after each refresh, for widgets that would rather react than poll.

Reading is cheap, but not free. Do not run a large loop over many entities in one widget every frame. The selection model computes its ability list once per refresh and shares it with every widget that asks.

A view model for an entity is created the first time you ask for it, and stays cached. When the entity is destroyed its view model fires On Invalidated, reports Is Alive false, and is discarded within about a second. Do not keep a view model reference across a destroyed entity. Ask again with the handle.

The Sein Entity View Model is a read-only lens on any entity.

  • Identity. Display Name, Description, Icon, Portrait, Identity Tag, Owner Player ID and Is Alive. Name, description, icon and portrait are read from the entity’s identity data once, when the view model is created.
  • Numbers. Get Attribute reads a number from any component the entity has, by component type and field name: SC_HealthData and Health. The value is the effective one, with every active effect applied, and it comes back as a float for display. Get Base Attribute reads the same field without effects, for displays such as “100 (+25)”. The field name takes a path like an effect’s modifier: VisionStamps[0].Radius. Both return 0 when the field is missing.
  • Whole components and tags. Has Component, Get Component Data and Get Tags.
  • Relation. Get Relation To Local Player returns Friendly, Enemy or Neutral, which is what a health bar’s colour or a nameplate needs.
  • Abilities. Get Abilities and Get Ability By Tag return Sein Ability Info for each ability, and Has Ability With Tag answers yes or no. The info holds its name, tag, icon, resource cost, cooldown and time remaining, target type, whether it is enabled, active, passive or on cooldown, and, when it is disabled, the first reason. “Enabled” means the ability would pass its activation checks if clicked now. Checks that need a target, such as range, run on the click.
  • Production queue. Get Production Queue lists what a building is making, front first, with each item’s name, icon, progress and whether it is stalled at completion.

Numbers read through Get Attribute are for display. Gameplay logic in an ability reads fixed-point values directly, and never uses a float that went through the UI.

Get Local Player View Model returns the local player’s Sein Player View Model. Get Resource takes a resource tag such as SeinARTS.Resource.Minerals and returns the balance as a float. Get All Resources, Can Afford, Has Tech Tag, Get Unlocked Tech Tags and Result (None while the player is still in the match) complete it.

The Sein Selection Model tracks the local player’s selection and gives you an entity view model for each selected unit.

  • Get Selected View Models, Get Selection Count, Is Entity Selected.
  • Get Primary View Model: the focused unit, or the first selected one when none is focused. Use it for an info panel. Get Active Focus Index is -1 when focus is on the whole selection.
  • Get Selection Abilities: the abilities of the whole selection, combined without duplicates. Use it for an action grid.
  • Get Selection Ability By Tag and Selection Has Ability With Tag for one specific button.
  • On Selection Changed fires when the selection or focus changes.

Combining follows set rules. For one ability across the selection, it is enabled if any selected unit can fire it, and it is on cooldown only if every unit holding it is. Its cooldown remaining is the shortest among them. To use an ability from a button, call Trigger Ability From Action Slot with the player controller and the ability tag. It fires an instant ability at once, or opens the targeter when the ability needs a target.

The Sein Minimap View Model is style-free data for a minimap you draw yourself:

  • World Bounds Min and World Bounds Max, and Ground Z: the play area and the ground height used to turn a click into a world point.
  • Blips: one per visible entity. A blip has a position in the map’s 0 to 1 space with north up, the entity’s relation to the local player, a size class, whether it is selected, the entity handle, and an optional icon from the entity’s identity.
  • Background Texture: the top-down texture of the level, or the override on the level volume.
  • Fog Texture: an overlay with the local player’s fog, or none when the map has no fog.

Blips skip entities that have no actor and entities carrying the tag SeinARTS.UI.Minimap.Hidden, which you add to a unit’s Base Tags on its SeinARTS Entity Bridge. An enemy in fog is skipped, and friendly and neutral units always appear. The fog texture’s size, update rate, blur and colours come from Project Settings > Plugins > SeinARTS under UI / Minimap, and a widget can override them. Add Fog and a Minimap builds the whole widget.

Use the SeinARTS UI Library for the map math: World To Minimap, Minimap Local To World, Get Minimap Rotation Degrees, Draw Camera Viewport To Render Target and Set Image Brush Resource.

Get Or Create Lobby View Model from the SeinARTS Lobby Library returns the world’s Sein Lobby View Model. It is an exec node, so put it in the execution chain. It shares one instance among every widget that asks.

It presents the replicated lobby: the Slots, with Try Get Slot for one by index; Is Host, Is In Lobby Session, Can Start Match; the local player’s slot, with Is Local Slot and Is Local Ready; Get Ready Count and Get Claimed Count, which count computer slots as ready; the selected map and the available maps; Is Map Shrink Safe, which tells you whether choosing a map would drop a claimed slot; and Get Current Map Team Count for a team picker. On Lobby Changed and On Local Slot Changed let a screen redraw. The view model only reads. The lobby buttons call the Lobby Library’s Request nodes. See Networking and Lockstep.

Some UI belongs on a unit: a health bar, a build progress bar, a nameplate. Two classes support it.

A Sein Entity Widget is a widget that knows which entity it shows. It has a Bound Entity, set for you, and it re-reads its display every tick. You override one function, Get Progress Display, and return a Sein Progress Display with three values: Visible, a Percent from 0 to 1, and an optional Label. The widget finds a Progress Bar named in Progress Bar Name (default ProgressBar) and a Text Block named in Progress Label Name and fills them. The default hides the bar. The On Entity Context Changed event tells you when the widget gets a new entity, such as when a pool reuses it.

The widget does not collapse itself when it is hidden. It turns transparent and stays hit-test invisible so it keeps ticking, and shows again when its display turns visible. A widget that is Collapsed does not tick and cannot show itself again.

Add a Sein Entity Widget Component to the unit Blueprint to show the widget in the world. It is a Widget Component, so you set Widget Class, Space (World or Screen) and Draw Size as usual. It binds to the actor it sits on, and it hands the entity to the widget. Build the HUD builds a health bar this way.

For overlays that follow many units on one HUD, use a Sein World Widget Pool. Initialize it with a panel and a widget class, then each frame call Release All, and Acquire a widget for each visible entity and position it with Project Entity To Screen and Is Entity On Screen. Widgets are reused instead of created.

A player selects three Soldiers. Their health is 100, 60 and 100. Each has Move, Stop and Attack, and the Soldiers also carry a Grenade ability with a cooldown. The grenade cooldowns have 20 seconds, 5 seconds and 0 seconds left.

  • Get Selection Count returns 3. The info panel uses Get Primary View Model, the first Soldier, and shows its name and its health from Get Attribute (Health 100 of MaxHealth 100).
  • Get Selection Abilities returns Move, Stop, Attack and Grenade once each.
  • Grenade is enabled, because the third Soldier can throw one. It is not on cooldown, because not every Soldier is. Its cooldown remaining reads 0, the shortest. The button shows ready.
  • The third Soldier throws, and its cooldown starts at 10. The remaining times are now 20, 5 and 10. All three are on cooldown, so Grenade is disabled, with a cooldown remaining of 5. The button’s sweep shows 5 seconds to go.
  • The second Soldier’s health bar is a Sein Entity Widget on that Soldier, built as in the demo. Its Get Progress Display returns Visible true because 60 is below 100, and Percent 0.6.
  • Collapsing a slot widget from its own Tick. A collapsed widget stops ticking and never returns. Have an always-visible parent call a Refresh function on its slots.
  • Writing to the simulation from a widget. View models and the nodes around them are read-only. Issue an order or call a Request node.
  • Keeping an entity view model after the entity dies. Handles are generational, and the view model is discarded. Get a new one by handle, and check Is Alive.
  • Doing gameplay arithmetic on a UI float. Get Attribute returns a float for display. Fixed-point values in abilities decide gameplay.
  • Expecting a minimap blip for every entity. Abstract entities, hidden-tagged entities and enemies in fog have none.
  • Treating Get Or Create Lobby View Model as a pure getter. It is an exec node. Wire it into the execution path, in Construct or Tick, and use its return value.