# Set UMG ViewModel for UUserWidget C++

**URL:** <https://forums.unrealengine.com/t/set-umg-viewmodel-for-uuserwidget-c/1711551>\
**Category:** UI\
**Tags:** User-Interface, unreal-engine, question\
**Created:** [February 25, 2024, 11:47am UTC](https://forums.unrealengine.com/t/set-umg-viewmodel-for-uuserwidget-c/1711551 "2024-02-25T11:47:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GhostDeveloper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GhostDeveloper](https://forums.unrealengine.com/u/GhostDeveloper)\
**Post date:** [February 25, 2024, 11:47am UTC](https://forums.unrealengine.com/t/set-umg-viewmodel-for-uuserwidget-c/1711551/1 "2024-02-25T11:47:25Z")

</div>

I try to implement new MVVM system into my project, but have a problem. In documentation for Manual ViewModel Creation Type says, that:

> The **Manual** creation method requires you to create an instance of the Viewmodel yourself somewhere in your application’s code, then assign it to the widget manually. The widget has a Viewmodel object reference, but it will have a null value until you assign a Viewmodel to it.

As i understand, i can set Viemodel into my .cpp file of my UUserWidget class or in Blueprint, but i didnt find any functions for this in c++, is it possible? Thanks!

---

<div class="post-metadata">

**Author:** ![reisandbeans](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/reisandbeans/32/88718_2.png) [@reisandbeans](https://forums.unrealengine.com/u/reisandbeans)\
**Post date:** [November 11, 2024, 8:26pm UTC](https://forums.unrealengine.com/t/set-umg-viewmodel-for-uuserwidget-c/1711551/2 "2024-11-11T20:26:35Z")

</div>

It seems those functions are created dynamically. I noticed this in the UMG Designer:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/6/6061af3d479696a434db6c32087b45e33c6beb0e.png)

And then peaking in the C++ code for the plugin,

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/2/e929e4325272f704a5bbb68180ab90cb3341b566.png)

---

<div class="post-metadata">

**Author:** ![Jesse\_OKD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jesse\_OKD](https://forums.unrealengine.com/u/Jesse_OKD)\
**Post date:** [April 10, 2025, 5:34pm UTC](https://forums.unrealengine.com/t/set-umg-viewmodel-for-uuserwidget-c/1711551/3 "2025-04-10T17:34:35Z")

</div>

Apologies for necro-ing this post again, but since it’s one of the first results on google, putting this here for future-me:

The system uses userwidget extensions.

```auto
if (UMVVMView* view = Cast<UMVVMView>(userWidget->GetExtension(UMVVMView::StaticClass())))
{
	FName vmName("MyViewModel");
	if (view->GetViewModel(vmName) == nullptr)
	{
		view->SetViewModel(vmName, LifeTime);
	}
}

```

---

<div class="post-metadata">

**Author:** ![SOSdude](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SOSdude](https://forums.unrealengine.com/u/SOSdude)\
**Post date:** [June 4, 2025, 1:10am UTC](https://forums.unrealengine.com/t/set-umg-viewmodel-for-uuserwidget-c/1711551/4 "2025-06-04T01:10:57Z")

</div>

Thank you so much Ive been looking for this since forever its nice to finally have an answer
