Basic Debugging Tools
When developing games with Unreal Engine (UE), you'll face problems like "it doesn't work as intended for some reason" or "no error but processing stops."
The most frequently used basic debugging tools for efficiently identifying bug causes are "Print String" and "Output Log." This article explains the basic usage and advanced techniques for these two tools.
Print String Basics and Applications
"Print String" is the most convenient and intuitive debugging technique. A node (Blueprint) or function (C++) that outputs specified strings to the game screen's top-left corner or Output Log.
Usage in Blueprint
In Blueprint, just inserting a Print String node in the middle of processing flow lets you confirm the processing executed or variable values at that point.
Practical Example: Checking Variable Values and Execution Confirmation
Example displaying current velocity and "Jump Executed!" message when character jumps.
// Blueprint execution flow
Event Jump -> Print String (String: "Jump Executed! Current Velocity: " + Get Velocity)
| Parameter | Role | Best Practice |
|---|---|---|
| In String | String to display. Often concatenates variable values. | Add prefix to identify which processing it's from (e.g., [Jump]). |
| Print to Screen | Whether to display on screen. | Use for confirmation during running game. |
| Print to Log | Whether to output to Output Log. | Use when screen display is distracting or permanent logs are needed. |
| Text Color | Screen display color. | Setting important messages to prominent colors (red, etc.) is convenient. |
| Duration | Time displayed on screen (seconds). | Set longer (e.g., 5.0 seconds) when tracing complex processing. |
| Key | Unique key identifying the message. | Messages with the same key are overwritten by newer ones. Very effective for continuous value checking. |
Value Tracking with Key
The Key parameter is a feature that makes Print String powerful as a debugging tool. Setting the same Key keeps the screen message updated to the latest value.
For example, when displaying character HP every frame in Tick event, setting a fixed Key value makes HP continuously update in real-time at the screen's top-left. This prevents the screen from being flooded with messages while tracking specific variable changes.
Using Output Log
If Print String is "convenient visual checking," "Output Log" is the debugging heart aggregating information from the entire UE system. Not just messages from Blueprint and C++, but engine warnings, errors, load information—all information is recorded here.
Opening and Basic Operations
Output Log opens from Window > Developer Tools > Output Log at the top of the editor.
- Filtering: The search bar at the top of the log window displays only messages containing specific keywords (e.g.,
Error,Warning,MyDebug). - Log Categories: UE logs are categorized like
LogTemp,LogBlueprint,LogAI, etc. Combined with filtering, extract only needed information.
Logging in C++: UE_LOG Macro
When outputting debug information to Output Log in C++, use the UE_LOG macro. This is the most standard debugging technique in C++ development.
// Define log category (usually use project name, etc.)
DEFINE_LOG_CATEGORY_STATIC(LogMyGame, Log, All);
// Example outputting warning message
UE_LOG(LogMyGame, Warning, TEXT("Player %s took damage. Remaining HP: %f"), *GetPlayerName(), CurrentHealth);
// Example outputting error message
if (TargetActor == nullptr)
{
UE_LOG(LogMyGame, Error, TEXT("Target actor is Null! Aborting process."));
return;
}
The second argument of UE_LOG (Warning, Error, Log, etc.) indicates log verbosity (importance).
| Verbosity | Role | Use Case |
|---|---|---|
| Error | Fatal problem. When game continuation is difficult. | Required resource load failure, Null pointer reference, etc. |
| Warning | Potential problem. Non-fatal error that should be fixed soon. | Deprecated function usage, unexpected input values, etc. |
| Log | Standard information message. | Processing start/end, variable value confirmation, etc. |
| Display | Important information that should be displayed to user. | When you also want it shown on screen as debug info. |
Output to Output Log from Blueprint
Blueprint's Print String node also outputs to Output Log by default (when Print to Log is checked). However, to specify more detailed log categories, it's common to create custom log output functions in C++ and call them from Blueprint.
Best Practices and Common Mistakes
Best Practices
| Practice | Details | Effect |
|---|---|---|
| Include context in logs | Include which class, which function, which variable's value in Print String and UE_LOG messages (e.g., [MyActor::Tick] Current HP: 100). | Even with many logs, instantly identify which processing it's from. |
| Use different verbosity levels | In UE_LOG, use Log for mere information, Warning for problem signs, Error for fatal problems. | Output Log filtering is maximally useful, enabling response based on problem urgency. |
| Use Print String Key | When tracking variables in frequently executed processing like Tick or Update, always set Key to keep screen clean. | Prevents screen from being flooded with debug messages while enabling real-time value checking. |
| Prepare debug boolean variable | Prepare a boolean variable like bDebugMode in classes to enable/disable complex debug logging, checking before log output. | When debugging is complete, disable all log output with one variable, preventing performance degradation in release builds. |
Common Mistakes
-
Ignoring Print String Duration:
- Mistake: Leaving
Durationat default 2.0 seconds, trying to follow messages that disappear instantly. - Solution: Set
Durationto 5.0 or 10.0 seconds depending on the processing to track, or useKeyto persist messages.
- Mistake: Leaving
-
Not checking Output Log:
- Mistake: Relying only on
Print Stringresults displayed on screen, missingWarningandErrorrecorded in Output Log. - Solution: Make it a habit to check Output Log
ErrorandWarningfilters when processing doesn't work as intended.
- Mistake: Relying only on
-
Using
printforstd::coutin C++:- Mistake: Using C++ standard output functions for debugging.
- Solution: Always use the
UE_LOGmacro which integrates with UE's framework. This provides benefits of UE's logging system like verbosity settings, filtering, and file output.
Choosing Between Print String and Output Log
Print String and Output Log are the most basic debugging tools in Unreal Engine development, but understanding their usage can dramatically reduce bug-fixing time.
| Tool | Main Use | Characteristics |
|---|---|---|
| Print String | Execution confirmation, real-time variable display on screen. | Convenient, intuitive. Value persistence via Key is powerful. |
| Output Log | System-wide error/warning monitoring, detailed logging from C++. | Persistent, filterable. Understand system depths. |
Debugging is part of the development process, and mastering these tools is the first step toward professional engineering. Always question "Did this processing really execute?" "What's this variable's value now?" and make it a habit to verify with Print String and Output Log.