Identifier "…" not declared in the current scope in Godot 4
By Eduardo Orellana · Updated
The name is not a variable, constant, function, class or autoload that the script can see from that line. print(speed) in a script with no speed declared fails to parse with Identifier "speed" not declared in the current scope. Declare it (var speed := 200.0), fix the spelling, or move the declaration out of the block that hides it.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
The analyzer resolves every bare name when the script loads: local variables in the enclosing blocks, then the script's members and its parent classes, then global classes, autoloads and engine singletons. A name found nowhere stops the script, and none of it runs.
Names are case-sensitive and scoped to their block. A var declared inside an if, a for or another function does not exist outside it.
When the name is a Godot 3 identifier that was renamed, the message adds the new name as a hint.
More on this: PhysicsTestMotionResult in Godot 4: Identifier "PhysicsTestMotionResult" not declared
Reproduce it
A script that prints a speed it never declares.
extends Node
func _ready() -> void:
print(speed)
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Parse Error: Identifier "speed" not declared in the current scope.
at: GDScript::reload (res://answers/identifier-not-declared-in-the-current-scope/repro.gd:4)
ERROR: Failed to load script "res://answers/identifier-not-declared-in-the-current-scope/repro.gd" with error "Parse error".
at: load (modules/gdscript/gdscript_resource_format.cpp:46)Fix it
Declare it as a member, where every function in the script can see it.
extends Node
var speed := 200.0
func _ready() -> void:
print(speed)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
200.0Declared inside a block
A variable declared in an if or a loop only exists inside it. Using it after the block ends is this error. Declare it before the block and assign it inside.
var target: Node = null
if enemies.size() > 0:
target = enemies[0]
print(target)
An autoload or class_name that is not registered
A name like GameState only exists once the autoload is added in Project Settings, Globals, or the script carries class_name GameState. Until then every use of it is this error.
Verified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: [gdscript_analyzer.cpp line 4689, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L4689), [gdscript_analyzer.cpp line 4687, the rename hint](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L4687).
More on this: AudioStreamSample in Godot 4: Identifier "AudioStreamSample" not declared
Questions
- Why does it work in another script?
- Members belong to their own script. Another node's variable is reached through that node: get_node("Player").speed, or an autoload for shared state.
- Does the error stop the whole game?
- It stops that script from loading. Nodes that use it run without it, and anything calling into it fails next.
Related
- Function "…()" not found in base self
- Cannot find member "…" in base "…"
- Every verified Godot 4 answer
- Cannot assign a new value to a constant in Godot 4
- Cannot get return value of call to "…()" because it returns "void" in Godot 4
- Cannot infer the type of "…" variable because the value is "null" in Godot 4
- How to get the class name of a node in Godot 4: get_class() and get_global_name()
- Trying to return a value of type "…" from a function whose return type is "…" in Godot 4
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free