Unreal Engine 4 has a built-in debug console that can be used for executing commands or "cheats" as Unreal calls them. The console is accessed by pressing the tilde key (it's to the left of the 1 key on most keyboards, and has ` and ~ on it).
Unreal provides many built-in commands like
stat fps for showing the frames per
second, but it is especially useful for adding your own debug commands or
By default, the console is only available in the editor, development and test builds (i.e. not shipping builds).
In order to add our own functions and make them available through the debug
console, we will need to create a subclass of
UCheatManager, and create
a subclass of
APlayerController if we do not have one already.
As always, we'll be using the naming conventions from the best practices
document, where we
prefix custom classes with a project-specific set of letters, in this example
Remember that you will also need to modify your level's GameMode to use this Player Controller subclass.
Now that we have a custom subclass of
UCheatManager, and we have made sure
that our player controller is using it, we can start adding our own functions.
Here are a few examples to get you going. What you will need will depend on your game!
How to Run your Cheats
Using the examples above, set a breakpoint in
open up the debug console with the tilde key, and type in the following:
You should see that NumCakes is 100, and Diameter is your default value of 1. Note that parentheses are not required when calling cheats from the console.
SetCakeName Delicious Cheesecake
NewName is "Delicious Cheesecake", note that we did not have to add quotation marks when calling the cheat command, it globbed all the subsequent text together into our single parameter. Nice!
Useful General-purpose Functions
The majority of functions in your cheat manager will be things that are specific to your game. For example in an RPG you might add cheats to give the player extra money or immediately complete certain quests.
However here are a few functions that are useful to have in general.
Please let me know if you have any of your own and I can add them here!