- KCoppinsIventis
- Posts: 12
- Joined:
Registering View Models in Unreal Engine C++
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'
Re: Registering View Models in Unreal Engine C++
Hi,
The factories for such components are registered automatically. The name of a native C++ UClass is of the form /Script/ModuleName.ClassName. We register such classes with the name ModuleName.ClassName. So, most likely reason is that the namespaces are wrong.
Hope this helps!
The factories for such components are registered automatically. The name of a native C++ UClass is of the form /Script/ModuleName.ClassName. We register such classes with the name ModuleName.ClassName. So, most likely reason is that the namespaces are wrong.
Hope this helps!
- KCoppinsIventis
- Posts: 12
- Joined:
Re: Registering View Models in Unreal Engine C++
That was exactly it, I have renamed my namespaces in my blend project to match those of my unreal module. Thanks for your help!
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 3 guests