Yes, I ran into this problem too. I have a BP_MyUserWidget, which has MVVM Viewmodel and Bindings setup. BUT as soon as I try to reference BP_MyUserWidget inside my C++ HUD class constructor, like this:
static ConstructorHelpers::FClassFinder<UMyUserWidget> BP_MyUserWidget(TEXT("/Game/UserWidgets/BP_MyUserWidget")); MyUserWidgetClass = BP_MyUserWidget.Class;
And I close and reopen the editor. My Viewmodel is gone and all of my bindings are too!? HELP
Ah, I suppose I cannot get the BP_MyUserWidget class inside the constructor, instead what I can do is something like:
MyUserWidgetClass = LoadClass<UMyUserWidget>(this, TEXT("/Game/UserWidgets/BP_MyUserWidget"));
Inside my C++ HUD BeginPlay(), or wherever I actually do the CreateWidget and AddToViewport etc. etc. Doing it this way, the Viewmodel and Bindings stay properly on the Blueprint, and don’t get removed after closing and reopening the editor.
Feels like MVVM plugin should throw some kind of error when you load the Blueprint UserWidget class at a bad time though?
OK, new problem if you’re using a UserWidget with UPROPERTY(meta=(BindWidget))
. Say you create a Canvas Panel like this:
UPROPERTY(meta=(BindWidget))
TObjectPtr<class UCanvasPanel> MyCanvasPanel;
and from your MVVM you’re setting up your Bindings too, then from BOTH the C++ side and the BP side, the Binding Name “MyCanvasPanel” will be occupied. And you won’t be able to package your project with the error:
Internal Compiler Error:
Tried to create a property MyCanvasPanel in scope SKEL_BP_MyUserWidget_C, but another object (ObjectProperty /Script/MyProject.MyUserWidget:MyCanvasPanel) already exists there.
from Source: /Game/UserWidgets/MyUserWidget.MyUserWidget
Currently, no idea how to fix that.