KCoppinsIventis
Topic Author
Posts: 11
Joined: 14 Mar 2024, 19:53

Registering View Models in Unreal Engine C++

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`:
<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>
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:
Cannot set value for 'DataTemplate.DataType', unknown type 'PauseMenu:PauseMenuViewModel'
Cannot set value for 'DataTemplate.DataType', unknown type 'HUD:HUDViewModel'
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?
 
User avatar
hcpizzi
Site Admin
Posts: 321
Joined: 09 Feb 2012, 12:40

Re: Registering View Models in Unreal Engine C++

18 Mar 2024, 20:19

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!
 
KCoppinsIventis
Topic Author
Posts: 11
Joined: 14 Mar 2024, 19:53

Re: Registering View Models in Unreal Engine C++

18 Mar 2024, 20:28

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] and 7 guests