The short answer
Start with the exact error and the smallest script or scene that reproduces it. Trace where the failing value comes from, change one thing at a time, and rerun the same scene. GDSense can explain likely causes and propose a fix when you explicitly attach the relevant context. If a request fails, your prompt stays available to Retry; review and test every change in Godot.
Start with a repeatable failure
A useful debugging report contains the complete error message, the script and line where it occurred, what you expected, and the steps that make it happen. Preserve that baseline before changing code so you can tell whether a proposed fix actually solved the original problem.
- 1
Reproduce the error
Run the same scene and write down the shortest sequence that triggers the failure.
- 2
Read the first relevant stack entry
Open the script and line named by Godot, then inspect the values and node references used there.
- 3
Reduce the search area
Focus on the failing function, its direct inputs, and the scene nodes it depends on before examining unrelated files.
Use GDSense with the relevant evidence
GDSense does not automatically inspect your whole project. Attach the smallest useful context and ask a concrete question. Add the scene only when node paths, signals, or attached scripts matter to the failure.
- 1
Attach the failing code
Use the open script or selected lines so the request includes the code named by the error.
@openscript - 2
Add scene context when it matters
Share the scene or a specific node when the error involves a missing node, signal, or scene-tree relationship.
@scene res://scenes/enemy.tscn --scripts - 3
Ask for a cause and a test
Include the exact error, expected behavior, and reproduction steps. Ask how to verify the proposed fix.
- 4
Review before changing files
Inspect the suggested edit. Protected changes in Agent Mode require your approval before they are applied.
- 5
Retry a failed request
Failed Chat and Agent-start requests keep your full prompt available. Retry resends the same prompt with the same mode and context. Work that fails before the AI service creates a response is refunded; an already-created response or completed Agent turn can remain billed if delivery fails later.
extends CharacterBody2D
@export var speed: float = 120.0
@onready var target: Node2D = get_node_or_null("../Player") as Node2D
func _physics_process(_delta: float) -> void:
velocity = global_position.direction_to(target.global_position) * speed
move_and_slide()@openscript
@scene res://scenes/enemy.tscn --scripts
Godot reports "Invalid access to property or key 'global_position' on a base object of type 'Nil'" on the velocity line. It happens when I run enemy.tscn by itself. Explain the likely cause, propose the smallest safe fix, and tell me how to verify it.How do I fix a null instance or a previously freed target?
First decide whether the reference is required or optional. In the example, enemy.tscn expects a sibling named Player that exists in the full game scene but not when the enemy scene runs alone. A guard prevents an invalid access; it does not create the missing Player or prove the scene is configured correctly.
For an optional target that can disappear during gameplay, check is_instance_valid() before using it and define the no-target behavior. For a required dependency, fix the assignment or instantiation order and report a clear setup error. Do not silently return from every failing function until the symptom disappears.
func _physics_process(_delta: float) -> void:
if not is_instance_valid(target):
velocity = Vector2.ZERO
move_and_slide()
return
velocity = global_position.direction_to(target.global_position) * speed
move_and_slide()- Run the enemy by itself: it should remain still without an invalid access.
- Run the complete scene: it should still pursue the assigned Player.
- Remove the target during play: it should stop on the next physics update.
- If targets respawn, assign the new instance explicitly; a cached reference does not retarget itself.
Why did a node path stop working after moving a scene?
Resolve a relative path from the node running the script, not from the scene root you happen to be viewing. Check the Remote scene tree while the failure is live: the runtime hierarchy may differ from the saved scene. Renaming, reparenting, or instancing a node elsewhere can invalidate a path that previously worked.
@onready delays a lookup until the node is ready; it does not make a wrong path correct or refresh a reference after a scene replacement. A scene-unique name can reduce hierarchy dependence within its valid scope, but it must be marked unique in the editor. For dependencies supplied by a parent, an exported typed node reference can make assignment clearer.
Godot Node lookup and lifecycle methodsHow do I separate signal bugs from syntax and import problems?
For signals, trace where the state changes, where the event emits, when the connection is created, and which runtime instance receives it. A listener connected after a one-time event will not receive that past event. Repeated updates may be repeated emissions, not duplicate connections.
For a parser error, inspect the reported line and the statement immediately above it: missing colons, inconsistent indentation, unclosed brackets, and a mismatched type can move the apparent failure downstream. Fix the first relevant parser error before evaluating gameplay behavior.
If an imported or renamed script appears stale, save the files, check for duplicate class_name declarations and path-case mismatches, and let the editor finish its import before retrying. Do not delete the .godot cache as a default debugging step. Capture the first import error and use a backed-up disposable copy for any cache-rebuild experiment.
@openscript
@scene res://ui/inventory.tscn --scripts
The initial inventory update emits before the HUD connects, so the first display is empty.
Explain the lifecycle and propose explicit initial rendering without adding per-frame polling.
Keep the existing signal payload and show how to test reopening the inventory.Verify the fix in Godot
- Run the exact scene and steps that originally produced the error.
- Confirm the debugger no longer reports the original failure.
- Test the normal gameplay path as well as the missing-node or empty-state path.
- Review the final diff and keep only changes you understand.
Keep in mind: A plausible explanation is not proof. Runtime behavior, Godot errors, and your project tests remain the source of truth.