Custom Console Commands
Custom console commands are for development or debugging (non-shipping) builds and used specifically for debugging or testing.
In shipping builds, Unreal strips out all custom commands.
Use cases
Custom console commands are for development or debugging (non-shipping) builds and used specifically for debugging or testing. In shipping builds, Unreal strips out all custom commands.
Examples of custom console commands you might write include:
- Setting health
- Setting time of day
- Setting currency
Supported classes
Unreal only allows custom console commands to be defined in a subset of classes, including:
- Game Mode: Typically where you will define custom console commands.
- Cheat Manager: Used for managing cheat functions.
- Player Controller: Handles player input and control.
- HUD: Manages the heads-up display.
- Pawn: Represents characters in the game.
- Player Input: Handles player input processing.
The Game Mode is typically where you will define custom console commands.
Defining a custom console command
Our custom console command is defined as a standard UFUNCTION
with the addition of the Exec
modifier, which tells Unreal this function should be exposed (and executable) via the console.
UFUNCTION(Exec)
void SetMaxAndCurrentHealth(float NewMax, float NewCurrent);
void ...GameModeBase::SetMaxAndCurrentHealth(float NewMax, float NewCurrent)
{
MaxHealth = NewMax;
CurrentHealth = NewCurrent;
}
Using a custom console command
When defining the function, any parameters included as part of the function signature will be input via the console using spaces.
(in your editor console): SetMaxAndCurrentHealth 750 750
(this sets our max health to 750 and our current health to 750)
Backlog
N/A