I used HUD as manager, set HUD to create widget, but still getting “CreateWidget can only be used on UUSerWidget children”
Which one is empty this time?
void ANonBattleWidgetsHUD::CreateCustomWidget(ENonBattleWidgetTypesEnum theWidgetType, class APlayerController* currentController)
{
if (theWidgetType == ENonBattleWidgetTypesEnum::NBWT_NONBATTLEMENU)
{
UNonBattleMenu_Widget* theWidget;
TAssetSubclassOf<class UNonBattleMenu_Widget> theClass;
theWidget = CreateWidget<UNonBattleMenu_Widget>(currentController, theClass.LoadSynchronous()); // Create Widget
if (!theWidget)
return;
theWidget->AddToViewport();// Add it to the viewport so the Construct() method in the UUserWidget:: is run.
theWidget->SetVisibility(ESlateVisibility::Hidden);// Set it to hidden so its not open on spawn
NonBattleWidgetMap.Add(theWidgetType, Cast<UBase_Widget>(theWidget));
}
}
tried the code slightly differently… thx to Some Korean Named Ocelot in Korean Unreal Naver Cafe.
void ANonBattleWidgetsHUD::BeginPlay()
{
Super::BeginPlay();
theWidget = CreateWidget<UNonBattleMenu_Widget>(GetWorld() , theClass.LoadSynchronous()); // Create Widget
if (!theWidget)
return;
theWidget->AddToViewport();// Add it to the viewport so the Construct() method in the UUserWidget:: is run.
theWidget->SetVisibility(ESlateVisibility::Visible);// Set it to hidden so its not open on spawn
NonBattleWidgetMap.Add(ENonBattleWidgetTypesEnum::NBWT_NONBATTLEMENU, Cast<UBase_Widget>(theWidget));
}
But Where is my custom widget… cannot see any result when I hit Play button