# UMG Viewmodel Basics

A simplified schematic to see how it should work.

<figure><img src="/files/MxsxwVWspVXjWzTlhdnM" 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mvvm.labutin.gg/umg-viewmodel-basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
