How can I create/customize my own console commands in C++?

Hi guys,

Could you guys teach me how to create my own console commands? I just want to create a console command like

Stat startfile

but I could not found the source code about that command. I read a lot of tutorial and know that I can use the UFUNCTION Exec, but it is said that can only get works on the some specific class. Therefore, Could you guys please teach me how to create a console command like Stat startfile or point out where the source code of that console command?

Thanks
Bests
YL

2 Likes

Check this out : A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

You can create your own console command and make it recognized everywhere. If your custom class wasn’t pawn/controller/gamemode, you need to put your custom class inside of of these class, and override the function to forward the function call as stated in the article.

As for Stat StartFile
Source\Developer\FunctionalTesting\Private\FunctionalTest.cpp (1285)

Other Relevant files includes:

  • BaseInput.ini (91)

  • Stats2.cpp (1277, 1293)

  • StasCommand.cpp

Alternatives:

Thank you! very helpful! May I ask an another silly question? If I constructed a new class inheriting the cheat manager, and that new class only has the UFUNCTIOIN Exec, will the UE4 recognize my custom console command after I compile or need I do anything else? I just started to learn the Unreal Engine weeks ago, and confused about how it works. I mean when the engine start to run, which file is first to run. What is the Unreal Engine work process?

If you inherit the cheat manager and built any functions in it, they will be recognized.

But you need to swap out the default cheat manager within APlayerController with the code below, in constructor, or its blueprint equivalent. (Go to details panel and type cheat manager)

AMyPlayerController::AMyPlayerController
{
    CheatClass = UMyCheatManager::StaticClass();
}

As for compilation, anythings tight to UFUNCTION() or UPROPERTY() will need to regenerate its generated.h, recompile it instead of hot reload for a better “life experience”.

The engine has too much code, I had no idea which one going to run first. I only sure about the inherited one because it is easier to place breakpoints. Engine breakpoints might not hit due to optimization.

2 Likes

Thank you so much! May I continue to ask a question? Could I create a console command like Stat StartFile that need not be called in the specific class? Really want to get all thing clear about the console command part…sorry to bother you a lot,

Sorry, I didn’t how to recreate something like stat startfile and I kinda panic I see the word threadsafe and dumps in that thing.

You might want to ask a very senior level programming dude for that architecture.

Thank you, dude, you has helped me a lot! the UE4 is too complicated…

Thank you, I am reading the Console Variable things now!

New link to 4.27 console vars page since Epic destroyed all links to their docs when releasing UE5: Console Variables in C++ | Unreal Engine Documentation

3 Likes