创建界面并且添加到窗口用蓝图创建的话 ,比较简单,本篇博文就不介绍了。有时候需要用C++ 添加已经创建好的界面蓝图到窗口,下面就简单介绍一下怎么用C++的方法添加(涉及到动态加载)
FString UiPath = TEXT("/Script/UMGEditor.WidgetBlueprint'/Game/Pack/HotUpdateToolsUi.HotUpdateToolsUi_C'");//动态加载UI 类
UClass* WidgetComponent = LoadClass<UUserWidget>(nullptr,*UiPath);
if (WidgetComponent)
{
UUserWidget* HotUi = UWidgetBlueprintLibrary::Create(GWorld, WidgetComponent, nullptr);//创建蓝图添加到窗口
HotUi->AddToViewport();
}
需要注意的是这里面的TEXT()的路径是用的引用,还要在后面添加上_C (这里是要特别注意的)
这里面用到的头文件如下
#include "Blueprint/WidgetBlueprintLibrary.h"