We have a plugin that extends the StaticMeshEditor, by adding a custom Tools Menu… The extension works, the menu shows up, and our delegates are called. The problem is, how do we get a reference back to the StaticMeshEditor instance that launched this menu item? There doesnt seem to be any context information passed to FUIAction delegates.
Heres our code:
struct FStaticMeshEditorExtensions
{
// ****************************************************************
void ApplyUVDisplacement()
{
// HOW TO??? Get the static mesh editor that called me?!?
}
// ****************************************************************
void FillToolsMenu(FMenuBuilder& InMenuBuilder)
{
InMenuBuilder.BeginSection("UVTools");
{
InMenuBuilder.AddMenuEntry(
LOCTEXT("StaticMeshEditorExtensionMenuApplyUVDisplacement", "Apply UV Displacement"),
LOCTEXT("StaticMeshEditorExtensionToolTipApplyUVDisplacement", "ApplyUVDisplacement"),
FSlateIcon::FSlateIcon(),
FUIAction(FExecuteAction::CreateRaw(this, &FStaticMeshEditorExtensions::ApplyUVDisplacement))
);
}
InMenuBuilder.EndSection();
}
// ****************************************************************
void GenerateToolsMenu(FMenuBarBuilder& InMenuBarBuilder)
{
InMenuBarBuilder.AddPullDownMenu(
LOCTEXT("StaticMeshEditorExtensionMenuTools", "Tools"),
LOCTEXT("StaticMeshEditorExtensionToolTipTools", "Opens a menu with tools for meshes"),
FNewMenuDelegate::CreateRaw(this, &FStaticMeshEditorExtensions::FillToolsMenu),
"Tools");
}
// ****************************************************************
void InstallExtensions()
{
// Get the StaticMeshEditor module
IStaticMeshEditorModule* staticMeshEditorModule = &FModuleManager::LoadModuleChecked<IStaticMeshEditorModule>("StaticMeshEditor");
if (staticMeshEditorModule == nullptr)
return;
// Create an extension to the static mesh editor menu
menuExtender = MakeShareable(new FExtender);
menuExtender->AddMenuBarExtension(
"Asset",
EExtensionHook::After,
NULL,
FMenuBarExtensionDelegate::CreateRaw(this, &FStaticMeshEditorExtensions::GenerateToolsMenu)
);
staticMeshEditorModule->GetMenuExtensibilityManager()->AddExtender(menuExtender);
}