How to open an editor widget on plugin click

Hi!

I’m working on a project and I would like to make my own plugin (with a button in the editor toolbar)

I have to open an editor widget, pretty simple right? But I’m really new in C++ and I can’t figure how to do this.

I only know that I have to put some code in here (it’s the UE example) :

void FTestToolbarbtnModule::PluginButtonClicked()
{
	// Put your "OnButtonClicked" stuff here
	FText DialogText = FText::Format(
							LOCTEXT("PluginButtonDialogText", "coucoucoucocuocuocuAdd code to {0} in {1} to override this button's actions coucou"),
							FText::FromString(TEXT("FTestToolbarbtnModule::PluginButtonClicked()")),
							FText::FromString(TEXT("TestToolbarbtn.cpp"))
					   );
	FMessageDialog::Open(EAppMsgType::Ok, DialogText);
}

Can you help me?

Thanks in advance!

Hey, I’m having this same issue. I was wondering if you ever figured it out?

Here is the solution: Load the editor utility blueprint first, then spawn and register it accordingly by UEditorUtilitySubsystem.SpawnAndRegisterTab

void FTestToolbarbtnModule::PluginButtonClicked() const
{
	UObject* WidgetObj = LoadObject<UObject>(nullptr, TEXT(" *Path of the Utility Widget*"));
	UEditorUtilityWidgetBlueprint* WidgetBP = static_cast<UEditorUtilityWidgetBlueprint*>(WidgetObj);
	UEditorUtilitySubsystem* EditorUtilitySubsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>();
	EditorUtilitySubsystem->SpawnAndRegisterTab(WidgetBP);
}
2 Likes

Thanks for posting this!

Two questions @Vahab if you can spare a moment? :slight_smile:

  1. Where should we actually put the Editor Utility Widget files? Do we move the “.uasset” files for the EUW into a path? That’s what I’ve been trying to do. I’ve moved them to here:
    {UNREALPROJECTNAME}\Plugins{pluginname}\Resources\EUW

  2. When you say PATH OF THE UTILITY WIDGET, is that a relative path? and is it just a path to a folder that we should do - or a path and then a .uasset item?

I’ve tried many ways but can’t figure it out.

The Editor Utility Widget could be anywhere, if it is in the main Content folder, the relative path should be started with
/Game/path of the utility widget
and if it is in your plugin folder, the path should be like this
/{PluginName}/path of the editor utility

for example:
/MyPlugin/EditorUI/EUW_MyEditorWidget

I am working on a new plugin that has a feature to do this without any CPP code, will be released soon!

1 Like