Average Reading Time: 1 minute

In this post we’re going to create our own custom console commands. Unreal Engine 4 provides a specifier named Exec, for the UFUNCTION macro which declares that the following function can be executed through the console window of the engine (to open up the console window press the ~ key in your keyboard). However, there is a catch – currently only specific classes execute the said functions. According to UE4 answershub, these classes are:

  1. Pawn
  2. PlayerController
  3. CheatManager
  4. GameMode
  5. PlayerInput and
  6. HUD

Creating console commands

For this post, I’ve created a blank C++ project. Then, I opened up the header file of my game mode and added the following functions:

Here is their implementation:

Save and compile your code, then in the default map in the World Settings make sure to specify your c++ (or the derived BP) game mode in the game mode override option:

game_mode

Then, when you press play if you open up your console you can execute the functions we’ve created above by typing their name and pressing enter.

In order to pass multiple parameters in the console window, type the name of your function and space your pamateres like so:

DoubleParamFunction 123.4323 5000

Here is my output after calling each function:

output_2

Share postShare on Facebook26Tweet about this on TwitterShare on LinkedIn0Share on Reddit0