Widget Class selection goes back to none when compiling

Hi all!

First of all, I am new to this forum, so if there is anything I can do better, or you have any feedback, I’m keen to hear it!

So here is my problem: I’m using Unreal Engine 4.27.1. I have created a C++ class called HealthWidget that inherits from UUserWidget. I have also created a blueprint class that derives from HealthWidget, called WBP_HealthWidget. I also have a CustomPawn C++ class that inherits from APawn, and a blueprint class that derives from CustomPawn, called BP_CustomPawn. I want to use the HealthWidget from the CustomPawn class, so I included this in CustomPawn.h:

image

Then in the BP_CustomPawn blueprint, I am selecting the WBP_HealthWidget, like so:

image

It lets me select it, but when I compile this blueprint, it goes back to None. I added some logs to check that this was not a UI problem, and that it was really selected but was not showing up correctly, but nothing.

Anyone knows what am I missing?

Thank you very much!

1 Like

You must be setting it to nullptr somewhere in your source code.

Either that, or you’re using hot reload.

@Natalo77 I am not assigning it anywhere else in the code, I just created the var and check if it exists. But I think I have seen something about Hot Reload, how can I check if I am using it? And how do I disable it? Thanks!

You need to do the following:

public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets") TSubclassOf<class UUserWidget> HealthWidgetTemplate;


private:
UPROPERTY() UHealthWidget* HealthWidget;

Then in your code you can create it:

if(HealthWidgetTemplate){
    HealthWidget = CreateWidget<UHealthWidget>(this, HealthWidgetTemplate, FName("MyName"));
}

It worked! Thanks!!