Trying WCode's UMG Widget c++ and... TSubclassOf Causing trouble...

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));
		
		
	}
}


I am pretty sure that I derived from UUserWidget class…

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

Weird… I solved it with awkwardness.

inside PlayerController BP, I manually set the widget class as BP version of the widget class… I been screwed up for no-brainer stuff.

Thank you so much! I was pulling my hair out, turns out this was the solution. I never knew playercontroller uses a widget subclass set in blueprint.