How to make an EditorUtilityWidget open/run via C++

I FINALLY GOT IT TO WORK!

If anyone is still wondering, since it’s hard to find the solution to this. I decided to share what I found.
I found this random chinese website, that posted like just a month ago and it shows a working way to open them via C++:

This is working for a Standalone Window Editor Plugin:

TSharedRef FVIR_ENVIRONMENTModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{

// load UMG Of BP
UBlueprint* UMGBP = LoadObject<UBlueprint>(nullptr, L"/Game/yaksueEditorUtilityWidgetBlueprint"); //Reference to your EditorUtilityWidget

// Modelled on the  UEditorUtilityWidgetBlueprint::CreateUtilityWidget()  Do it again 
TSharedRef<SWidget> TabWidget = SNullWidget::NullWidget;
{

	UEditorUtilityWidget* CreatedUMGWidget = nullptr;// Created UMG Control 

	UClass* BlueprintClass = UMGBP->GeneratedClass;
	TSubclassOf<UEditorUtilityWidget> WidgetClass = BlueprintClass;
	UWorld* World = GEditor->GetEditorWorldContext().World();
	if (World)
	{

		if (CreatedUMGWidget)
		{

			CreatedUMGWidget->Rename(nullptr, GetTransientPackage());
		}
		CreatedUMGWidget = CreateWidget<UEditorUtilityWidget>(World, WidgetClass);
	}
	if (CreatedUMGWidget)
	{

		TabWidget = SNew(SVerticalBox)
			+ SVerticalBox::Slot()
			.HAlign(HAlign_Fill)
			[
				CreatedUMGWidget->TakeWidget()
			];
	}
}

Don’t forget to do this: #include “Editor/Blutility/Classes/EditorUtilityWidget.h”

Also add
“UMGEditor”,
“Blutility”,
“UMG”

to your private dependencies in the Build.cs of the plugin.

All credits go to this post: Learn to use UMG as an editor control in the unreal engine

3 Likes