Custom Context Menu entries in Unreal Editor

Hello,

I have created a tutorial for you guys on how to add custom Editor Only context menu entries for your custom actor objects.

The tutorial can be found in the Code Wiki https://wiki.unrealengine.com/Custom_Context_Menu_for_Actors_in_Editor.

I implemented this because I wanted a neat way to access some editor only methods for my actor classes and there was no way I could easily access them via the editor.

Hope this will help some people who need to do this as well.

Enjoy,
Chrys

PS : feedback and comments are welcome. :slight_smile:

This is cool, thanks. Make that PR this is worth it.

Thanks for this tutorial :smiley:

hope Epic will adjust their source and make it easier

Hey Chrys, thank you for writing a tutorial. However this is not the recommended way to extend the editor’s context menus. Good news though! No engine changes should be needed at all to accomplish this, and your tutorial could be much shorter! :slight_smile: So for something like what you’re doing here, where you want to have a custom menu entry in the right click menu for actors in the level viewport, we have a menu extension system that should support that. In fact, many of Epic’s own built-in features are using the same menu extension system that you guys will use.

For an example of this, check out how the Blueprint Editor adds it’s own extensions to the Level Editor. The code to look at is in BlueprintEditorModule.cpp. Search for FLevelEditorModule::FLevelViewportMenuExtender_SelectedActors. This what you’ll use to register custom menu items to be displayed when the user right clicks on actors. In your callback, you’ll usually write some code that looks at which types of actors were right clicked on, and only show your custom menu item when the actors are of the type that you are looking for.

Your post highlights to me that we need better official documentation for this, but in the meanwhile if you need advice about best practices for UE4 plugins and menu extensions, please post here and we’ll try to help out.

–Mike

Hello Mike,
thanks for your reply, I will check the code you mentioned out when I get time. I have worked with some exstentiors before here in Unreal but I wasn’t aware of the code for adding them to the menu. You say that most of the unreal stuff uses them internally. I must have gotten unlucky and only found the place of code where it builds the menus and there weren’t any extensions interfaces in the code as far as I can remember. Anyhow I will check this out :).

About the documentation, yes please, it is definitely lacking in that area of the code. I tried search quite extensively for information about how to add custom right click contextual menus but couldn’t find anything so that is how I decided to invest a couple of hours to see how the actor menu is build and so I hooked into that. :slight_smile:

Chrys

Many of the editor features were initially designed before we had completed the menu extensibility system, so you will see all sorts of examples of editor menu setup throughout the engine code. The newer modules and plugins generally do things the right way, which is to use extension callback delegates with FMenuExtenders to inject new menu entries without modifying engine source code.

Did you want to update your tutorial?

–Mike

I haven’t yet had a chance to look into the code just yet , so I can’t update the tutorial :-/ . Ofc feel free to maybe give a simple example there / change my suggestion so it won’t misslead others. :slight_smile:

Hi Mike-
I’d like to extend the ComponentActions context menu (built in SSCSEditor.cpp). I’m using 4.6.1 currently. I’d love to use the “recommended” approach to extending menus. However, as far as I can tell, unlike the level editor Context Menu, this particular context menu has no support for extensibility (yet?). It seems like I need to edit SSCSEditor::CreateContextMenu() directly in order to extend it. Is that correct? Is there a plan to add extensibility to the component context menu? If so, what’s the timeframe on that?

Thanks,
-Josh

1 Like