UE使用cpp代码打开EditorUtilityWidget

平时写ue小工具的基本都是使用EditorUtilityWidgetBlueprint; 如果工具稍微一多,直接通过ContentBrowser的话,不是很方便!

png

所以我比较喜欢在Menu

void FMyEditorModule::OpenFrameworkConfig()
{
    // 因为我是放置在plugin中的,所以我这里不是/Game
	FString assetPath = TEXT("EditorUtilityWidgetBlueprint'/MyPlugin/Editor/BP_FrameworkConfig.BP_FrameworkConfig'");
	auto asset = UEditorAssetLibrary::LoadAsset(assetPath);
	UEditorUtilityWidgetBlueprint* EditorWidget = Cast<UEditorUtilityWidgetBlueprint>(asset);
	UEditorUtilitySubsystem* EditorUtilitySubsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>();
	EditorUtilitySubsystem->SpawnAndRegisterTab(EditorWidget);
}

assetPath中,测试过在直接使用/MyPlugin/Editor/BP_FrameworkConfig.BP_FrameworkConfig加载也是没有问题的