How to load a blueprint class and spawn it in C++?

You can also use LoadClass
As:

UClass* WidgetClass = LoadClass<UUserWidget>(nullptr, TEXT("/Script/UMGEditor.WidgetBlueprint'/Game/UMG/BPW_Show.BPW_Show_C'"));
if (WidgetClass)
{

auto widget = CreateWidget(this->m_pPlayerControllerFace.Get(), WidgetClass);
if(IsValid( widget))
this->m_pPlayerControllerFace->setCurrentWidge(widget);

}


你还可以使用 LoadClass
如:

UClass* WidgetClass = LoadClass<UUserWidget>(nullptr, TEXT("/Script/UMGEditor.WidgetBlueprint'/Game/UMG/BPW_Show.BPW_Show_C'"));
if (WidgetClass)
{

auto widget = CreateWidget(this->m_pPlayerControllerFace.Get(), WidgetClass);
if(IsValid( widget))
this->m_pPlayerControllerFace->setCurrentWidge(widget);

}