While our game may be running without any issues in the editor or even in…
BeginPlay and GLog Explanation
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:
Hi, thank you for your incredible lessons, they’re awesome, really well explained and designed, easy to comprehend, like putting a step forward at a time.
I just had a simple question:
What’s the main difference between
‘GLog->Log(“Some string”);’
and
‘UE_LOG(LogClass, Log, TEXT(“Some other string”));’
I mean, GLog is a macro which is getting() the instance of the FOutputDeviceRedirector class which has log() functions from his parent that I found there: https://docs.unrealengine.com/latest/INT/API/Runtime/Core/Misc/FOutputDevice/index.html
But UE_LOG() is a macro using FMsg struct which contains log and messaging functions but allow me to make a more complex logging system with “categories” ( https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime ).
How does it differ technically speaking ? Which one should I use for what purpose ?
Thanks again for all your amazing work. =D
First of all, thank you for your feeback!
I like to use UE_LOG for warnings and errors since it provides a more “visual” feedback to the user (because of the yellow and red colors of warnings and errors respectively). I use GLog when I’m debugging my own code or when I want to stay informed about something which is not crucial. To be honest I’m not aware of their technical differences.
-Orfeas