I created UUserWidget and stored it’s pointer into TMap. I didn’t use AddtoViewport right after the pointer is created at first because I want to use AddtoViewport when I want on runtime. However, the pointer is filled with garbage value when I access it to use AddtoViewport(). Do I have to use AddtoViewport() right after creating UUserWidget?
Is there any solution about this situation?
Thanks.
<.h>
TMap<eWIDGET, UUserWidget*> WidgetMap;
<.cpp>
void AFP_PlayerController::BeginPlay()
{
FName Path = TEXT("WidgetBlueprint'/Game/WidgetBP/FP_StatusWidget_BP.FP_StatusWidget_BP_C'");
TSubclassOf<UFP_StatusWidget> Widget = Cast<UClass>(StaticLoadObject(UClass::StaticClass(), NULL, *Path.ToString()));
UFP_StatusWidget* StatusWidget = CreateWidget<UFP_StatusWidget>(this, Widget);
WidgetMap.Add(STATUS, StatusWidget);
Path = TEXT("WidgetBlueprint'/Game/WidgetBP/FP_Stage_BP.FP_Stage_BP_C'");
TSubclassOf<UFP_StageWidget> Widget2 = Cast<UClass>(StaticLoadObject(UClass::StaticClass(), NULL, *Path.ToString()));
UFP_StageWidget* StageWidget = CreateWidget<UFP_StageWidget>(this, Widget2);
WidgetMap.Add(STAGE, StageWidget);
}