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

This post was great, but as written can cause crashes when the level changes. So I did it this way calling the UEditorUtilityWidgetBlueprint method rather than rebuilding it:

TSharedRef<SDockTab> FYourModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{

	// load YourWidget as BPClass
	UEditorUtilityWidgetBlueprint* UMGBP = LoadObject<UEditorUtilityWidgetBlueprint>(nullptr, L"/Game/YourEUWBP"); 

	TSharedRef<SDockTab> SpawnedTab = UMGBP->SpawnEditorUITab(SpawnTabArgs);

	return SpawnedTab;
	
}

This works for me as a Menu Tab

4 Likes