Logging to screen in C++ with Unreal

In order to log to the screen in Unreal from code, as you can with PrintString in blueprints add the following:

1
#include <Runtime/Engine/Classes/Engine/Engine.h>

And then you can call a method on the global engine object.

1
2
3
4
5
6
GEngine->AddOnScreenDebugMessage(
-1, // Adds a new message, like the BP
0.5f, // Duration of message
FColor::Cyan.WithAlpha(64), // Color and transparancy!
"Some text"
);

Whatever you do, don’t just include the main Engine.h as it’ll tank your compile times by including everything.