Hi,
We’re working on a custom tooling plugin for a project and I was looking into adding new entries to the context menu that is displayed when you right-click on an element in the Hierarchy tab of a widget.
From what we can see elsewhere in the engine the usual method seems to be to:
- declare an array of MenuExtender delegates in a module’s header file
- plugins/modules that want to extend the menu retrieve a module’s MenuExtender array and add new delegates to it
- the menu that will be extended retrieves the module’s MenuExtender array, executes the delegates and adds FExtenders they return to the menu
The change we are proposing would be to add this code snippet to the UMGEditorModule.h file:
`public:
virtual TArray& GetAllWidgetContextMenuExtenders() { return WidgetContextMenuExtenders; }
private:
TArray WidgetContextMenuExtenders;`
And also add this code snippet to the FWidgetBlueprintEditorUtils::CreateWidgetContextMenu function in the WidgetBlueprintEditorUtils.cpp file like this:
`void FWidgetBlueprintEditorUtils::CreateWidgetContextMenu(FMenuBuilder& MenuBuilder, TSharedRef BlueprintEditor, FVector2D TargetLocation)
{
BlueprintEditor->PasteDropLocation = TargetLocation;
TSet Widgets = BlueprintEditor->GetSelectedWidgets();
UWidgetBlueprint* BP = BlueprintEditor->GetWidgetBlueprintObj();
//------------------------CHANGE START--------------------------------------------------------
IUMGEditorModule& UMGEditorModule = FModuleManager::LoadModuleChecked(“UMGEditor”);
const TArrayIUMGEditorModule::FWidgetContextMenuExtender& MenuExtenderDelegates = UMGEditorModule.GetAllWidgetContextMenuExtenders();
TArray<TSharedPtr> Extenders;
for (int32 i = 0; i < MenuExtenderDelegates.Num(); ++i)
{
if (MenuExtenderDelegates[i].IsBound())
{
Extenders.Add(MenuExtenderDelegates[i].Execute(BlueprintEditor));
}
}
TSharedPtr MenuExtender = FExtender::Combine(Extenders);
MenuBuilder.PushExtender(MenuExtender.ToSharedRef());
//------------------------CHANGE END--------------------------------------------------------
MenuBuilder.BeginSection(“Edit”, LOCTEXT(“Edit”, “Edit”));
{
…
}
MenuBuilder.EndSection();
}`
This change would benefit all other projects and users that want to add custom actions and functionalities to the widget context menu as you can see in the attached screenshot. Let me know if the change seems appropriate.