hello,
So I have been trying to extend some engine code to allow me to add custom menu entries upon right clicking my custom Actor objects in the Editor.
I can now correctly receive a functioncall to my Actor that has been selected and the right mouse button has been clicked on in the object browser.
Here is the body of my method that is being called :
void AMyCustomActor::AddCustomMenuEntries(class FMenuBuilder& MenuBuilder)
{
FMyCustomEditorCommands::Get().MapActions(this);
FMyCustomEditorCommands::Get().AddToMenu(MenuBuilder);
}
where FMyCustomEditorCommands is defined as
class FMyCustomEditorCommands : public TCommands < FMyCustomEditorCommands >
{
public:
FMyCustomEditorCommands ();
virtual void RegisterCommands() override;
static void MapActions(AActor* InActor);
static void AddToMenu(class FMenuBuilder& MenuBuilder);
protected:
public:
TSharedPtr< FUICommandInfo > DoSomethingCustom;
private:
TSharedPtr< FUICommandList > MyCommandsList;
};
and implemented as
FMyCustomEditorCommands::FMyCustomEditorCommands() :
TCommands<FMyCustomEditorCommands>(TEXT("MyCustomEditorCommands"), NSLOCTEXT("MyEditor", "FMyCustomEditorCommands", "My-Editor"), NAME_None, FEditorStyle::GetStyleSetName()),
MyCommandsList(new FUICommandList())
{
}
void FMyCustomEditorCommands::RegisterCommands()
{
UI_COMMAND(DoSomethingCustom, "My Custom Entry", "Does something really awesome..", EUserInterfaceActionType::Button, FInputGesture());
}
void FMyCustomEditorCommands::MapActions(AActor* InActor)
{
Register();
AMyCustomActor* pMyActor = Cast<AMyCustomActor>(InActor);
if (pMyCustomActor)
{
Get().MyCommandsList->MapAction(
Get().DoSomethingCustom, FExecuteAction::CreateStatic(&AMyCustomActor::SomeStaticMethod));
}
}
void FMyCustomEditorCommands::AddToMenu(class FMenuBuilder& MenuBuilder)
{
MenuBuilder.BeginSection("MyCustomStuff", FText::FromString("Custom"));
{
MenuBuilder.AddMenuEntry(Get().DoSomethingCustom);
}
MenuBuilder.EndSection();
}
so then I just make sure I register FMyCustomEditorCommands once at startup of the editor and I can now see my custom menu added to the existing actor menu. (it works because i added a virtual function call on Actor and i call it from where in the engine it builds the menu for all selected actors.)
but I have one problem… even though i can see and click on my custom menu entry, it doesnt actually execute any code.
I have put breakpoints in each step of the code and it always hits right up to the point where it registers the static method to the menu. But the static method is never called. Am I missing something ? I can post also the code for where i call the “AddCustomMenuEntries” but it is fairly trivial.
Any idea why my function even though it is registered isnt being called ?