# Listen existing command event in an editor plugin?

**URL:** <https://forums.unrealengine.com/t/listen-existing-command-event-in-an-editor-plugin/358400>\
**Category:** C++\
**Tags:** command, trigger, unreal-engine, editor, UE4, question, CPP\
**Created:** [May 24, 2016, 10:36am UTC](https://forums.unrealengine.com/t/listen-existing-command-event-in-an-editor-plugin/358400 "2016-05-24T10:36:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [May 24, 2016, 10:36am UTC](https://forums.unrealengine.com/t/listen-existing-command-event-in-an-editor-plugin/358400/1 "2016-05-24T10:36:40Z")

</div>

I am working on an editor plugin with a custom EdMode.

I would like to do something when the user performs an action (in my case: select the translate tool, with the UI button or the keyboard shortcut).

How can I access the command (for example the SelectTranslateTool command)?

How can I react to event triggered by this command?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [May 24, 2016, 10:46am UTC](https://forums.unrealengine.com/t/listen-existing-command-event-in-an-editor-plugin/358400/2 "2016-05-24T10:46:35Z")

</div>

ok, it seems the line 228 of SEditorViewport.cpp will help me:

```
CommandListRef.MapAction(
	Commands.TranslateMode,
	FExecuteAction::CreateSP( ClientRef, &FEditorViewportClient::SetWidgetMode, FWidget::WM_Translate ),
	FCanExecuteAction::CreateSP( ClientRef, &FEditorViewportClient::CanSetWidgetMode, FWidget::WM_Translate ),
	FIsActionChecked::CreateSP( this, &SEditorViewport::IsWidgetModeActive, FWidget::WM_Translate ) 
	);

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [May 24, 2016, 11:13am UTC](https://forums.unrealengine.com/t/listen-existing-command-event-in-an-editor-plugin/358400/3 "2016-05-24T11:13:49Z")

</div>

I don’t know how to access the EditorViewport ☹

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [May 24, 2016, 12:41pm UTC](https://forums.unrealengine.com/t/listen-existing-command-event-in-an-editor-plugin/358400/4 "2016-05-24T12:41:19Z")

</div>

It took me 2 hours to make this code:

```
FLevelEditorModule& LevelEditor = FModuleManager::GetModuleChecked<FLevelEditorModule>( TEXT("LevelEditor") );
TWeakPtr<SLevelEditor> LevelEditorInstance = LevelEditor.GetLevelEditorInstance();
if(LevelEditorInstance.IsValid())
{
    TSharedPtr<SLevelEditor> LevelEditorInstancePtr = LevelEditorInstance.Pin();
    TSharedPtr<FUICommandList> LevelEditorCommands = LevelEditorInstancePtr->GetLevelEditorActions();
    
    const FEditorViewportCommands& Commands = FEditorViewportCommands::Get();
    LevelEditorCommands->MapAction(Commands.TranslateMode, FExecuteAction::CreateUObject( APB::Instance, &APB::SetWidgetMode, 0 ));
    LevelEditorCommands->MapAction(Commands.RotateMode, FExecuteAction::CreateUObject( APB::Instance, &APB::SetWidgetMode, 1 ));
    LevelEditorCommands->MapAction(Commands.ScaleMode, FExecuteAction::CreateUObject( APB::Instance, &APB::SetWidgetMode, 2 ));
}

```

and it does not work, it overrides the commands instead of extending them.

It’s so hard to find documentation and help in UE.
