Course contentsShow
← Unity Game Development
Lesson 65 of 8281. Unity FoundationsFree lesson

Mastering Console Logging and Log Types

Learners will categorize diagnostic messages using Debug.Log, Warning, and Error methods to filter and track runtime information effectively.

In this lesson, you will learn how to use different types of console messages to track your game's runtime behavior and identify issues efficiently.

When building games, the Unity Console is your primary window into what your code is doing behind the scenes. Instead of just printing everything as a generic message, you can categorize your output to make it easier to filter the noise. Unity provides three distinct methods for this:

Debug.Log

Use Debug.Log for general information. This is your "bread and butter" for tracking gameplay events, such as confirming a player has picked up an item or checking the current value of a variable during movement calculations.

Debug.Log("Player health is now: " + health);

Debug.LogWarning

Use Debug.LogWarning when something unexpected happens that doesn't necessarily break your game, but might lead to problems later. For example, if your code detects that an object is missing a required component but has a fallback plan, a warning helps you spot potential architectural debt without stopping the simulation.

Debug.LogError

Use Debug.LogError for critical failures. If a calculation results in a null reference or a vital game system fails to initialize, this is the tool to use. Errors appear in red and are vital for catching "silent" bugs that occur while testing your input mappings or transformation logic.

Filtering Your Output

At the top of the Unity Console window, you will see three small icons representing these types. By clicking these icons, you can toggle them on or off. If you are debugging complex movement logic, you might want to hide all Warnings and Errors to focus solely on the sequence of Debug.Log messages you have placed in your scripts. Mastering this filtering allows you to cut through the clutter during intense playtesting sessions.

Key Takeaway: By using Debug.Log, Debug.LogWarning, and Debug.LogError appropriately, you turn the Unity Console into a powerful diagnostic tool that categorizes information so you can isolate bugs and track game state changes with precision.