Skip to content

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.

Download for macOSDownload for WindowsDownload for Linux

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: Expected end of statement after variable declaration, found "Identifier" instead: setget in Godot 4

Reproduce it

A script that prints a speed it never declares.

GDScript
extends Node

func _ready() -> void:
	print(speed)

What Godot 4.7.2 prints

Output
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.

GDScript
extends Node

var speed := 200.0

func _ready() -> void:
	print(speed)

What the fixed script prints

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

200.0

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

Prompt
My Godot 4 project prints this error: "Parse Error: Identifier "speed" not declared in the current scope.". Find where it comes from and fix it. 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. Then run the game headless and check that Godot's output no longer shows it.

Declared 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.

GDScript
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.

More on this: PhysicsTestMotionResult in Godot 4: Identifier "PhysicsTestMotionResult" not declared

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, gdscript_analyzer.cpp line 4687, the rename hint.

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.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free