Using Cheat Manager in Unreal Engine 4

The cheat manager in Unreal Engine 4 is a class that handles commands useful for making testing much easier. In fact it’s a container for most of the exec cheat functions. Those functions can be implemented in many places – GameInstance classes or PlayerController classes but it’s good to keep them in one place in order to have the project more organized.

There are plenty of commands in the base Cheat Manager already – you can check all of them in the following file.
Engine\Source\Runtime\Engine\Classes\GameFramework\CheatManager.h
But if you want to extend the Cheat Manager in your game there are few steps that must be followed.

To start implementing your Cheat Manager – create a class that inherits from the base one:

MyCheatManager.h
#pragma once
 
#include "CoreMinimal.h"
#include "GameFramework/CheatManager.h"
#include "MyCheatManager.generated.h"
 
UCLASS()
class CHEATTEST_API UMyCheatManager : public UCheatManager
{
    GENERATED_BODY()

    UFUNCTION(exec)
    void TestMyCheatManager();
};
Notice the exec function. This keyword tells the engine that this is an executable command.

The Cheat Manager is an integral part of the Player Controller, so you must tell your Player Controller which Cheat Manager it should use:

MyPlayerController.cpp
#include "MyPlayerController.h"
#include "MyCheatManager.h"
 
AMyPlayerController::AMyPlayerController(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{
    CheatClass = UMyCheatManager::StaticClass();
}
Remember to set your Player Controller to be used in a Game Mode:

CheatTestGameModeBase.cpp
#include "CheatTestGameModeBase.h"
#include "MyPlayerController.h"
 
ACheatTestGameModeBase::ACheatTestGameModeBase(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{
    PlayerControllerClass = AMyPlayerController::StaticClass();
}
In the end – implement the Cheat Manager’s function:

MyCheatManager.cpp
#include "MyCheatManager.h"
#include "Engine.h"
 
void UMyCheatManager::TestMyCheatManager()
{
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Hello My Cheat Manager!"));
}
And it is done! When we type testmycheatmanager (commands are case insensitive) into the console (press ` on PC or tap the screen with four fingers on mobile device) the nice message should appear on the screen: