Lesson 7 of 9 · 21m
Debugging the Runtime, Not the Fantasy
Use the remote scene tree, breakpoints, error output, visual debugging, and isolated repro scenes to inspect what the game is actually doing.
Game debugging is humiliating because the bug is usually not where you are looking. You wrote the player script, so you stare at the player script while the collision layer is wrong, a hidden control consumes input, and the object spawned under another parent. Godot's tools are strongest when you use them to inspect reality instead of defending your mental model.
Start with the remote scene tree
Run the game from the editor and open the debugger's remote tree. It shows the live hierarchy, not the .tscn you intended to create. Verify:
Is the node present?
Is it under the expected parent?
Does its runtime name match the path?
Which script is actually attached?
Is it inside the viewport or outside it?Most Node not found reports are answered here in under a minute. The remote tree also exposes runtime-spawned nodes that never appear in the editor dock.
Breakpoint with a hypothesis
Do not stop everywhere and hope. Write one sentence first: "I expect health to be 5 when damage is called." Then break at damage, inspect amount, current, and the caller.
func damage(amount: int) -> void:
print_debug("damage", amount, "before", current)
current = maxi(current - amount, 0)print_debug is useful context, but logs show what happened while breakpoints let you interrogate why. In tight loops, remember that stopping time can itself alter timing-sensitive behavior.
Visualize physics before rewriting physics
Godot can draw collision shapes, navigation, rays, and other spatial information in debug views. A raycast that never hits is usually pointed the wrong way, using the wrong mask, or testing the wrong physics space:
var query := PhysicsRayQueryParameters2D.create(global_position, target_position)
query.collision_mask = 1 << 2
var result := get_world_2d().direct_space_state.intersect_ray(query)Mask arithmetic is easy to botch. Put named constants around layer bits rather than sprinkling binary literals through gameplay scripts.
Isolate in a repro scene
When the world contains forty moving pieces, make a scene with three:
ReproProjectileTunneling.tscn
├── Shooter
├── ThinWall
└── StaticCameraPreserve the failure while deleting unrelated variables. Record seed, version, scene, input mode, platform, and whether the bug appears in editor or export. Exported-only failures often involve resource paths, timing, case sensitivity, or focus.
Field notes
printspam can hide ordering because output is asynchronous relative to frames.- Tool scripts and editor plugins can retain state; restart the editor when behavior becomes impossible.
- Remote inspection is useless if you are looking at a different instance than the one you launched.
- If
queue_freeis involved, distinguish stale references from newly spawned lookalikes. - A repro scene that removes the bug is still evidence: add pieces back one at a time.
Was this lesson helpful?