0
0
Unityframework~10 mins

Debug.Log for debugging in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Debug.Log for debugging
Start Program
Code runs
Debug.Log called
Message sent to Console
Developer reads message
Fix or understand code
End or continue
The program runs and when Debug.Log is called, it sends a message to the Unity Console for the developer to see and understand what is happening.
Execution Sample
Unity
void Start() {
    int score = 10;
    Debug.Log("Score is: " + score);
}
This code prints the current score value to the Unity Console when the game starts.
Execution Table
StepActionCode LineMessage Sent to Console
1Start method calledvoid Start() {
2Variable score set to 10int score = 10;
3Debug.Log called with messageDebug.Log("Score is: " + score);Score is: 10
4End of Start method}
💡 Start method finishes, Debug.Log message shown in Console
Variable Tracker
VariableStartAfter Step 2After Step 3Final
scoreundefined101010
Key Moments - 3 Insights
Why do I see the message 'Score is: 10' in the Console?
Because at step 3 in the execution_table, Debug.Log sends the combined string and score value to the Console.
Does Debug.Log change any variables or stop the program?
No, as shown in variable_tracker and execution_table, Debug.Log only prints messages and does not affect variables or program flow.
What if I want to see different values during the game?
You can call Debug.Log anytime with updated values; each call sends a new message to the Console for you to read.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what message is sent to the Console at step 3?
A"Debug.Log called"
B"score = 10"
C"Score is: 10"
D"Start method called"
💡 Hint
Check the 'Message Sent to Console' column at step 3 in execution_table
At which step is the variable 'score' assigned the value 10?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Code Line' columns in execution_table for variable assignment
If you remove Debug.Log line, what changes in the execution_table?
ANo message sent to Console at step 3
BVariable 'score' will not be set
CProgram will stop immediately
DStart method will not run
💡 Hint
Debug.Log is responsible for sending messages; removing it means no Console output
Concept Snapshot
Debug.Log(message) prints messages to Unity Console.
Use it inside methods to see variable values or program flow.
It does not change variables or stop the program.
Helps find bugs by showing what the program is doing.
Call it anytime to check current values or states.
Full Transcript
When you run a Unity program, Debug.Log lets you print messages to the Console. This helps you see what your code is doing. For example, if you have a variable score set to 10, calling Debug.Log("Score is: " + score) will show "Score is: 10" in the Console. This does not change the score or stop the program. You can use Debug.Log anywhere to check values and understand your program better.