x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to get context in an editor menu extension

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);
 }
Product Version: Not Selected
Tags:
more ▼

asked Nov 13 '14 at 07:54 PM in C++ Programming

avatar image

Helius
26 2 5 7

avatar image Begounet Dec 20 '17 at 09:05 AM

Hello,

It is a really old thread but right now, I am getting the exact same issue. Do you have some news or does someone have a new idea to get the StaticMeshEditor instance ?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Eventually, I just found a way. You can use FAssetEditorManager to watch what asset was opened, and from here, find the associated editor. It is the same function used to check if the asset is already opened when you try to open again the same asset (giving the focus to the editor instance).

 void FMyClassEditor::Initialize()
 {
     FAssetEditorManager::Get().OnAssetEditorOpened().AddRaw(this, &FMyClassEditor::OnAssetEditorOpened);
 }
 
 void FMyClassEditor::OnAssetEditorOpened(UObject* AssetOpened)
 {
     IAssetEditorInstance* assetEditorInstance = FAssetEditorManager::Get().FindEditorForAsset(AssetOpened, false);
     FStaticMeshEditor* staticMeshEditor = (FStaticMeshEditor*)(assetEditorInstance);
 }




more ▼

answered Dec 20 '17 at 09:53 AM

avatar image

Begounet
933 32 27 50

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question