Registering View Models in Unreal Engine C++
Posted: 18 Mar 2024, 18:26
Hi there,
I was looking at this layered UI example as I have some HUD and I wanted to open a pause menu. I have a master user control `MainView` with my `HUDView` user control and a `PauseMenuView`. I also have ViewModels defined for each view which is the name of the view with the Model suffix. I have the following definition inside the `MainView`:
I have set the data context to my `MainViewModel` which handles toggling the `PauseMenuView`, exactly the same as the sample. It works perfectly within Blend. When loading into Unreal Engine, I do the same and manually set the MainViewModel to my c++ code-behind implementation. However I get the following errors on rendering:
I assume this is because I havent registered my view models. However, as per the Sample I have made my view models `UObjects`, how can I register them as UObjects? Or is there something else I'm missing?
I was looking at this layered UI example as I have some HUD and I wanted to open a pause menu. I have a master user control `MainView` with my `HUDView` user control and a `PauseMenuView`. I also have ViewModels defined for each view which is the name of the view with the Model suffix. I have the following definition inside the `MainView`:
Code: Select all
<UserControl.Resources>
<DataTemplate x:Key="PauseMenuViewModelDataTemplate" DataType="{x:Type PauseMenu:PauseMenuViewModel}">
<PauseMenu:PauseMenuView/>
</DataTemplate>
<DataTemplate x:Key="HudViewModelDataTemplate" DataType="{x:Type HUD:HUDViewModel}">
<HUD:HUDView/>
</DataTemplate>
</UserControl.Resources>
Code: Select all
Cannot set value for 'DataTemplate.DataType', unknown type 'PauseMenu:PauseMenuViewModel'
Cannot set value for 'DataTemplate.DataType', unknown type 'HUD:HUDViewModel'