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?
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 )
);
I don’t know how to access the EditorViewport
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.