Hi, I used a soft connection in the HUD to get the blueprint Widget created. Restarting the editor will cause the MVVM attached to the Widget to disappear.
HUDMain.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/HUD.h"
#include "HUDMain.generated.h"
UCLASS()
class GAMEDEMO_API AHUDMain : public AHUD
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AHUDMain();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
private:
TSubclassOf<UUserWidget> UI_MainClass;
UUserWidget* UI_Main;
};
HUDMain.cpp
#include "HUD/HUDMain.h"
#include "Blueprint/UserWidget.h"
// Sets default values
AHUDMain::AHUDMain()
{
static ConstructorHelpers::FClassFinder<UUserWidget> UI_Main_BPClass(TEXT("/Script/UMGEditor.WidgetBlueprint'/Game/BP/UI/UI_Main_BP.UI_Main_BP_C'"));
if (UI_Main_BPClass.Succeeded())
{
UI_MainClass = UI_Main_BPClass.Class;
}
}
// Called when the game starts or when spawned
void AHUDMain::BeginPlay()
{
Super::BeginPlay();
UI_Main = CreateWidget<UUserWidget>(GetWorld(), UI_MainClass);
UI_Main->AddToViewport();
}
Before restarting the editor:
After restarting the editor: