Issue with extending the menu with a plug-in

Translated question (from Japanese):

Based on IntroTutorials plug-in, I tried to extend a menu using my own plug-in. Though I succeeded in implementing the code as shown below, there was an issue where the editor crashed when opening the Window menu after unloading the module.

#include "MyPluginPrivatePCH.h"

class FMyPlugin : public IMyPlugin
{
    virtual void StartupModule() OVERRIDE;
    virtual void ShutdownModule() OVERRIDE;

    void WindowMenuExtension(FMenuBuilder& MenuBuilder);

    TSharedPtr<FExtender> Extender;
};

IMPLEMENT_MODULE( FMyPlugin, MyPlugin )

void FMyPlugin::StartupModule()
{
    Extender = MakeShareable(new FExtender);
    Extender->AddMenuExtension("WindowLocalTabSpawners", EExtensionHook::After, NULL, FMenuExtensionDelegate::CreateRaw(this, &FMyPlugin::WindowMenuExtension));
    FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
    LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(Extender);
}

void FMyPlugin::ShutdownModule()
{
    if (Extender.IsValid() && FModuleManager::Get().IsModuleLoaded("LevelEditor"))
    {
       FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
       LevelEditorModule.GetMenuExtensibilityManager()->RemoveExtender(Extender);
    }
}

void FMyPlugin::WindowMenuExtension(FMenuBuilder& MenuBuilder)
{
    //...
}

The actual inconvenience is only that I have to restart the editor every time I develop. Though I know this is not an urgent issue, I’d appreciate it if you could investigate and address it. Also, I’m using the engine 4.1. Please let me know if there is any workaround on the issue.

–Asked by k-ohashi

Original Question

I´ve encountered the same issue. To me it seems like the Plugin is loaded before the MainMenu is generated and thus the Extenders are copied towards another ExtensibilityManager. Thus by removing it from the MenuExtensibilityManager doesn´t do anything…