> For the complete documentation index, see [llms.txt](https://mvvm.labutin.gg/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mvvm.labutin.gg/umg-viewmodel-basics.md).

# UMG Viewmodel Basics

A simplified schematic to see how it should work.

<figure><img src="https://2666578692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FprL5jbtTDARElFG53w1w%2Fuploads%2Fzp3U3bK7s8gFgKA1RQJw%2FScreenshot_2024-06-08_at_13.42.30.png?alt=media&amp;token=23784a90-d5c1-43e8-82e9-565ffcaa06cc" alt="" width="563"><figcaption></figcaption></figure>

## 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.
