How to make a simple menu in the editor with plugin

So I have made a custom project plugin which now works via command console and I would like to make some UI functionality for it by extending the editor.

What I would like to do is add a new menu item next to ‘help’ which has its own items like ‘settings’ like the picture below. I am able to add buttons to the toolbar and anywhere in the existing menus like file, edit, help but not create a completely new menu entry. How would I do this?

Then when I press settings, I would like to have a pop up window where I can set certain properties much like the detail PropertyEditor but a lot simpler:

133831-detail.jpg

I tried following a live stream on YouTube about extending the editor but it is going a bit too fast for me as I am a beginner in UE4 and I’m getting compile errors with the code shown there. Is there someone who can help me?

Thank you very much!

What you are wanting to do is extend the “Main Menu Bar” for the UE4 Editor. To understand how to do this, let us look at some code to begin with to see how it is created in the UE4 Editor Source Code. For simplicity’s sake, we will go top down from the highest module and trace the code to see how it is constructed.

We enter in first with the Level Editors Main Frame which is a Slate Widget:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/LevelEditor/Private/SLevelEditor.cpp#L177

It all starts here with this function to create the menu bar tabs in the Level Editor Menu:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/LevelEditor/Private/LevelEditorMenu.cpp#L126

And then the main frame module loads in the menu here:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/LevelEditor/Private/LevelEditorMenu.cpp#L380

Which contains the Help Menu, found here:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/MainFrameModule.cpp#L245

Which is really just a wrapper for the static MainMenu code found here:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/Menus/MainMenu.cpp#L382

And your help menu items are found right here:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/Menus/MainMenu.cpp#L360

So, what does all of that mean? Well, now you have all the examples you need to build a menu option tab in the main frame of the level editor as well as look at the code to see how it builds the menu options and the action lists for when an option is clicked. Exciting right! So, how to add it after the Help tab? You need to grab the mainframe module for the level editor and then call the extensibility manager to add a menu extension immediately after the Help button in the Help section.

The key here is the extender that we want to tack the menu option onto.

FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked("LevelEditor"); TSharedPtr MenuExtender = MakeShareable(new FExtender()); MenuExtender->AddMenuExtension("WindowLayout", EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FPLUGIN_NAMEModule::AddMenuExtension)); LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);

NOTE: This can be done by getting it via code here, note this is all example code here. Found here:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Plugins/Editor/PluginBrowser/Templates/Basic/Source/PLUGIN_NAME/Private/PLUGIN_NAME.cpp#L33

This will bind everything for you. Now, to get commands going, you need to define what the buttons do in the submenu. If you look at the examples I gave before, you can see how Help does this.
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/Menus/MainMenu.cpp#L283

And the commands are created here, but you would want to create your own in your plugin:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/Frame/MainFrameActions.h

And check out files here to see how to bind commands:
https://github.com/EpicGames/UnrealEngine/tree/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/Frame

3 Likes

Thank you for the extensive answer! Just what I needed to push me in the right direction:) I got my sub menu working now next to the help menu, now only for the settings window. I think I get how it works with the other commands so I should be fine from here. Thanks again!

No problem! Always glad to help. It really is extremely useful to go to the source code and find out how the devs did it originally. The hardest part is finding the starting point for all that code. Good luck on the rest of your project!

Hey,

i cannot figure out how to add a menu to the Main Menu Frame, can you share an example of how you get you menu to show up beside the Help menu ?

Sure be nice if the links worked. I bet there was a lot of useful information at one point in time.

They work, you just need to be signed in to Github with an account that has access to the Unreal source code.

Forgot how I got that setup, but it’s somewhere on the Unreal developer docs.

Took me a bit to figure that out too.

For anyone still working on that, the key is “MenuExtender->AddMenuBarExtension” instead of “MenuExtender->AddMenuExtension”.

The method you assign to the delete should then take “FMenuBarBuilder& MenuBuilder” instead of “FMenuBuilde& MenuBuilder”.

FMenuBarbuilder has a method called “AddPullDownMenu”, and now you can work forward from here on how to use that method and extend those menus:
https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Editor/MainFrame/Private/Menus/MainMenu.cpp#L333

1 Like

All the links to github on this page are now broken, is the technique different in UE5.0/5.1?

All of the links are linked to specific commit SHAs, so unless Epic overwrote their git history (unlikely) the more likely scenario is that you are not logged into GitHub with an account that is part of the Epic Games organization. If you have not done so, follow the instructions here: GitHub - EpicGames/Signup: Information about signing up for a free Epic Games account, and getting access to UnrealEngine source code..

As far as compatibility, I have not created a custom menu item in Unreal Engine 5. While most of the concepts are the same, there may be breaking changes between 4 and 5. I am currently writing a plugin with a custom editor in 5.0. If I come across this scenario again, I can reply with the steps for version 5.