Option 1: Adding a Menu Button Action
This option involves adding a straightforward actionable button to the editor's menu, which, when clicked, executes a predefined command.
Implementation using RegisterMenus
:
cppCopy code// MyModule.cpp
void MyModule::StartupModule()
{
MyModuleCommands::Register();
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(MyModuleName, FOnSpawnTab::CreateRaw(this, &MyModule::SpawnMyPluginTab));
}
void MyModule::RegisterMenus()
{
FToolMenuOwnerScoped OwnerScoped(this);
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Tools");
FToolMenuSection& Section = Menu->AddSection("MyModuleCommands", LOCTEXT("MyCommands", "My Module Commands"));
Section.AddMenuEntryWithCommandList(
MyModuleCommands::Get().OpenPluginWindow,
PluginCommands,
NAME_None,
LOCTEXT("OpenMyWindow", "Open My Window"),
LOCTEXT("OpenMyWindowTooltip", "Opens my custom plugin window."),
FSlateIcon(FMyModuleStyle::GetStyleSetName(), "MyCommandIcon")
);
}
Option 2: Creating a Submenu with Various Options
Creating a submenu allows you to group multiple related actions under a single menu heading, organizing the user interface more effectively.
Implementation using RegisterMenus
:
// MyModule.cpp
void MyModule::RegisterMenus()
{
FToolMenuOwnerScoped OwnerScoped(this);
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Tools");
FToolMenuSection& Section = Menu->AddSection("MyModuleSubmenu", LOCTEXT("MySubmenu", "My Module Submenu"));
// Creating a submenu
Section.AddSubMenu(
"MySubmenu",
LOCTEXT("MySubmenuLabel", "My Submenu"),
LOCTEXT("MySubmenuTooltip", "Explore actions available in My Module"),
FNewToolMenuDelegate::CreateRaw(this, &MyModule::FillMySubmenu),
false,
FSlateIcon(FMyModuleStyle::GetStyleSetName(), "MySubmenuIcon")
);
}
void MyModule::FillMySubmenu(UToolMenu* Submenu)
{
Submenu->AddMenuEntry(
MyModuleCommands::Get().OpenPluginWindow,
LOCTEXT("OpenWindowLabel", "Open Window"),
LOCTEXT("OpenWindowTooltip", "Open the main window of My Module."),
FSlateIcon(FMyModuleStyle::GetStyleSetName(), "OpenWindowIcon")
);
// Additional commands can be added here
}
PreviousUnreal Editor: adding a custom menuNextSpawning a tab when button clicked (similar to content directory etc)
Last updated