UMG Viewmodel Basics

A simplified schematic to see how it should work.

What is a Viewmodel?

A Viewmodel (VM) is a design pattern that separates presentation logic from business logic and data in a game.

Why use a Viewmodel?

  1. Separation of concerns: Separates UI logic from business logic.

  2. Improved testability: Easier to write unit tests for logic independent of UI.

  3. Reusability: Logic can be used in different parts of the interface.

  4. Simplified development: Developers can work on UI and logic independently.

Advantages over traditional methods

Compared to direct property/function binding in UMG:

  1. Less coupling: UI doesn't depend directly on game logic.

  2. Easier to maintain: Changes in logic don't require changes in UI.

  3. Cleaner code: Less logic in Widget Blueprints.

  4. Better performance: Fewer direct calls to game objects.

How does UMG Viewmodel work?

  1. Model: Contains data and business logic.

  2. Viewmodel: Transforms model data into a format convenient for display.

  3. View: UMG widget that displays data from the Viewmodel.

  4. Resolver: Connects Viewmodel and View.

Last updated