Assigned UUserWidget* inside of another widget is always reset after compile

Hi,
I try to dynamically create an interface using C++, but having an issue with UUserWidget.

The image attached shows some widgets assigned to the custom parent widget declared in C++ which is then placed within the main HUD widget of my project.

279845-ui-01.png

Here is declaration of the Type Button widget (other widgets declared the same way):

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu")
    UUserWidget * TypeButton;

My issue is that after the project is closed or code being compiled the assigned widget values are reset to None. I understand it happens because of the pointers being used, but how do I fix that?

This is after recompile:

279846-ui-02.png

Check your BeginPlay function and constructor in both the code and the blueprint, it’s likely being overwritten in one of those. If thatS not the case try changing EditAnywhere to EditDefaultsOnly

Thanks for the reply. I tried to change properties to EditDefaultsOnly, but it didn’t work. Regarding the Begin play and constructor, here is my code:

void UMyBadWidget::NativeConstruct()
{
	Super::NativeConstruct();

	HorizontalBox = Cast<UHorizontalBox>(GetWidgetFromName(*FString("Container")));

	HorizontalBox->ClearChildren();
	if (Interface.Num() > 0)
	{
		for (int idx = 0; idx < Interface.Num(); ++idx)
		{
			if (auto button = Cast<UUW_Button>(Interface[idx].TypeButton))
			{
				HorizontalBox->AddChildToHorizontalBox(button);
			}
		}
	}
}

I see no obvious reason assignment is reset…

I think I fixed the issue I had. Here is what I did in the header:

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu")
		TSubclassOf<UUserWidget> TypeButton;

cpp:

    HorizontalBox->ClearChildren();
	if (Interface.Num() > 0)
	{
		for (int idx = 0; idx < Interface.Num(); ++idx)
		{
			if (auto button = CreateWidget<UUW_Button>(GetWorld(), Interface[idx].TypeButton))
			{
				HorizontalBox->AddChildToHorizontalBox(button);
			}
		}
	}