While developing, you should have a way to output messages so you can check what’s happening in your game. Unreal Engine provides different ways to do that, so you can choose what is best for your needs. In this tutorial you are going to see the GLog function.
Enabling the Output Log in UE Editor
The message that I’m going to display will not appear on Viewport. Instead, it’s going to appear in the output log. To display the Output Log into the Editor:
- Go to your UE4 Editor
- Click on the Window on the top left corner
- Select Developer Tools
- Select Output Log
The default position of the Output Log is docked next to your Content Browser as the following image shows:
Logging a message in the BeginPlay function
The BeginPlay function of an Actor, is executed when one of the following conditions is true:
- When the game starts, if the Actor is already placed in the level and we press the Play button.
- When the Actor is spawned into the active level.
For this case, I created an Actor named LogActor and typed in the following code inside the BeginPlay function:
In order to test if BeginPlay and GLog actually work:
- Compile your project
- Create a Blueprint which inherits the LogActor class
- Place the above Blueprint somewhere in the test level
- Click Play
- Check your Output Log
If you followed all the steps your output should contain the “Hello from C++” message as seen in the image below: