Hello, I am trying to create an instance of a UMG widget using c++. The widget was created using the UMG editor.
I am working in the character files, in the character.h I have:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
TSubclassOf<UUserWidget> WidgetTemplate;
UUserWidget* WidgetInstance;
The WidgetTemplate is being set in the blueprint derived from the character class.
Then in the BeginPlay function in the character.cpp I am trying to use the CreateWidget function to set the value of WidgetInstance like so:
if (WidgetTemplate)
{
WidgetInstance = CreateWidget<UUserWidget>(this, WidgetTemplate);
if (WidgetInstance nstance) {
//let add it to the view port
WidgetInstance ->AddToViewport();
}
}
The problem arises with the CreateWidget function.
Any help would be appreciated.
Thanks,
Gubbing.