Skip to content

Instantly share code, notes, and snippets.

@ashe23
Created February 18, 2020 11:39
Show Gist options
  • Select an option

  • Save ashe23/132619544fcfcf2fa3df38549acdd5b3 to your computer and use it in GitHub Desktop.

Select an option

Save ashe23/132619544fcfcf2fa3df38549acdd5b3 to your computer and use it in GitHub Desktop.
Adding to Menu Entries in UE4 editor
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class CustomTestPlugin : ModuleRules
{
public CustomTestPlugin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PublicIncludePaths.AddRange(
new string[] {
"CustomTestPlugin/Public"
// ... add public include paths required here ...
}
);
PrivateIncludePaths.AddRange(
new string[] {
"CustomTestPlugin/Private"
// ... add other private include paths required here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"TestCPP"
// ... add other public dependencies that you statically link with here ...
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"LevelEditor",
"EditorStyle",
// ... add private dependencies that you statically link with here ...
}
);
DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "CustomTestPlugin.h"
#include "LevelEditor.h"
#include "Misc/Attribute.h"
#define LOCTEXT_NAMESPACE "FCustomTestPluginModule"
void FCustomTestPluginModule::StartupModule()
{
UE_LOG(LogTemp, Warning, TEXT("Starting Module...."));
// Create the Extender that will add content to the menu
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
//MenuExtender->AddToolBarExtension("Content", EExtensionHook::Before,);
MenuExtender->AddMenuExtension(
"LevelEditor",
EExtensionHook::After,
NULL,
FMenuExtensionDelegate::CreateRaw(this, &FCustomTestPluginModule::AddMenuEntry)
);
LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}
void FCustomTestPluginModule::ShutdownModule()
{
UE_LOG(LogTemp, Warning, TEXT("Stopping Module...."));
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}
void FCustomTestPluginModule::AddMenuEntry(FMenuBuilder & MenuBuilder)
{
// Create Section
MenuBuilder.BeginSection("CustomMenu", TAttribute<FText>(FText::FromString("Category/Section Name")));
{
MenuBuilder.AddSubMenu(FText::FromString("My Submenu"),
FText::FromString("My submenu tooltip"),
FNewMenuDelegate::CreateRaw(this, &FCustomTestPluginModule::FillSubmenu));
}
MenuBuilder.EndSection();
}
void FCustomTestPluginModule::FillSubmenu(FMenuBuilder& MenuBuilder)
{
// Create the Submenu Entries
MenuBuilder.AddMenuEntry(
FText::FromString("Menu Entry 1"),
FText::FromString("Menu Entry 1 Tooltip"),
FSlateIcon(),
FUIAction(FExecuteAction::CreateRaw(this, &FCustomTestPluginModule::MenuCallback1))
);
}
void FCustomTestPluginModule::MenuCallback1() {
UE_LOG(LogTemp, Warning, TEXT("Action 1!"));
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FCustomTestPluginModule, CustomTestPlugin)
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine.h"
#include "Modules/ModuleManager.h"
class FToolBarBuilder;
class FCustomTestPluginModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
private:
void AddMenuEntry(class FMenuBuilder& MenuBuilder);
void FillSubmenu(FMenuBuilder& MenuBuilder);
void MenuCallback1();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment