Skip to content

UI with MVVM: Blueprint patterns (ViewModels, bindings, cues) โ€‹

๐Ÿ“š UI & MVVM Documentation โ€‹

MVVM System: โ€‹

UMG & Widget System: โ€‹

UI Architecture Tutorials: โ€‹


๐ŸŽจ MVVM Architecture โ€‹

What/Why: Keep gameplay out of Widgets. MVVM makes UI robust and testable: ViewModels hold state; Widgets display and bind.

Prereqs

  • Plugins: Model-View-ViewModel (MVVM)

Steps

  1. Create ViewModel BP classes
  • VM_PlayerStatus: Health (float), Stamina (float), HasInteract (bool), InteractPrompt (text)
  • VM_InputHints: Move (text), Jump (text), Interact (text)
  1. Create Widgets and bind
  • WBP_HUD: progress bars bound to VM_PlayerStatus, prompt text bound to VM_PlayerStatus.InteractPrompt
  • WBP_InputHints: texts bound to VM_InputHints
  1. Route game events to ViewModels
  • Player Pawn components emit events (OnDamage, OnStaminaChanged, OnTraceHitInteractable)
  • In a UI Coordinator (Actor or Subsystem), listen and update ViewModels (no logic in Widgets)
  1. Show/Hide UI via state
  • Use Gameplay Tags (UI.HUD.Visible) to toggle visibility
  • For menus, swap mapping context to IMC_UI and pause gameplay

Data

  • DataAssets: DA_UITheme for colors/fonts/sizes; DA_InputDisplay for platform-specific glyphs

Networking

  • ViewModels exist on owning client only; replicate underlying game state to drive them

Performance

  • Avoid ticking Widgets; rely on bindings and events

Testing

  • Toggle HUD tag โ†’ widgets visible/hidden
  • Damage player โ†’ Health bar updates
  • Look at interactable โ†’ Interact prompt shows correct text

Suggested prompts โ€‹

  • โ€œUE 5.6 Blueprints only. Define VM_PlayerStatus (Health, Stamina, HasInteract, InteractPrompt) and bind it in WBP_HUD. Show where to update the ViewModel from Pawn events.โ€
  • โ€œExplain how to avoid game logic in Widgets with MVVM. Provide a small โ€˜UI Coordinatorโ€™ pattern in Blueprints.โ€
  • โ€œHow do I toggle HUD visibility with a Gameplay Tag and switch input contexts for UI?โ€
  • โ€œList common MVVM pitfalls in UE 5.6 and how to debug broken bindings quickly.โ€

Prompts for this example

  • โ€œGiven VM_PlayerStatus and WBP_HUD progress bars, show the nodes to update Health/Stamina from a HealthComponent event.โ€
  • โ€œProvide Blueprint nodes to show/hide the HUD using tag UI.HUD.Visible and swap to IMC_UI when visible.โ€

โš™๏ธ Core Systems

3 of 7 completed