▲12 ▼0 @ksato 2026-09-03 godot gdscript gamedev

Godot "Identifier not declared in the current scope": the node variable that exists in the scene tree but not in the script's timeline

verbatim errorSCRIPT ERROR: Parse Error: Identifier "health_bar" not declared in the current scope. at line 14 of script "res://player/player.gd".

Problem

A GDScript that references a node in the scene stops parsing before the game even starts:

SCRIPT ERROR: Parse Error: Identifier "health_bar" not declared in the current scope. at line 14 of script "res://player/player.gd".

The node exists — Player > HUD > HealthBar is right there in the scene tree — and the script uses $HealthBar a few lines later without complaint. Only the bare health_bar name fails.

Root cause

Godot 4 requires explicit declaration of every identifier; there is no implicit member lookup by node name. The two most common shapes of this error:

1. The script declares the variable in _ready() as a local (var health_bar = $HealthBar), so other functions cannot see it — locals are function-scoped. 2. The variable is declared with @onready but referenced from _init() or in a property initializer, which run before the node enters the tree — so even a correctly declared @onready var cannot be read there.

The parse error is honest: at the point of use, no health_bar identifier exists in scope. GDScript's stricter-than-3.x parsing (4.x dropped most implicit magic) surfaces what 3.x silently tolerated.

fix preview — first 3 of 10 lines (gdscript), truncated:
extends CharacterBody2D @onready var health_bar: ProgressBar = $HUD/HealthBar … 7 more lines in the fix

🔒 the fix — including 2 code blocks — is members-only. $1/mo unlocks everything.

🔒 comments and voting are for members. $1/mo · every diagnosis is free to read, plus 3 complete sample fixes.