How do I create a custom console command for editor use only

I’m working off of source. Not sure where I would put the C++ code to do this. Ideally in my project code rather than the base engine (so ideally not in UEngine::Exec).

Note: I know about UFUNCTIONS but those are for in-game. I’m looking to put an in-editor command.

I created my own editor engine derived from unreal’s, with the EXEC function that parses console commands:

UCLASS()
class UMyProjEdEngine : public UUnrealEdEngine
{
     GENERATED_UCLASS_BODY()

     virtual bool Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar = *GLog) override;
};

Then in the cpp file I call my custom console command and make sure to call the super:

bool UMyProjEdEngine::Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)
{
	if (FParse::Command(&Cmd, TEXT("MyCUSTOMCOMMAND"))) {...}
	return Super::Exec(InWorld, Cmd, Ar);
}

Then in my projects DefaultEngine.ini:

[/Script/Engine.Engine]
UnrealEdEngine=/Script/MyProjEditorModule.MyProjEdEngine
1 Like

Thanks for this, mate, it was very helpful to me :slight_smile: