Quick answer: A type hint, cast or type test names a class GDScript does not know. Either the name is a Godot 3 class (KinematicBody2D is now CharacterBody2D), the script that defines it has no class_name line, the name is misspelled, or Godot’s global class list is out of date. Rename the type, add class_name, load the script into a constant with preload(), or reload the project to rebuild the list.
Type names in GDScript are looked up in a fixed set of places: built-in types, engine classes, classes your project registered with class_name, and names declared in the current script. When the name after a colon is in none of them, the script fails to parse. In a project ported from Godot 3 the answer is nearly always a rename. In a new project it is usually a missing class_name, and on a build server it is a class list that was never generated. This guide walks through each, with a rename table, the two sibling messages that point at a different file, and what deleting the .godot folder costs you.
- The exact error
- What causes it
- How to find which cause is yours
- Fix 1: replace Godot 3 class names
- Fix 2: register your class with class_name
- Fix 3: get the type from preload instead
- Fix 4: name inner classes through their owner
- Fix 5: rebuild the global class list
- Fix 6: addons, GDExtension and C#
- How to confirm the fix
- When players see it
- Related guides
- Frequently asked questions
The exact error
Could not find type "KinematicBody2D" in the current scope.
Could not find type "Enemy" in the current scope.
Run the project with the error in place and the log shows the script being rejected:
SCRIPT ERROR: Parse Error: Could not find type "Enemy" in the current scope.
at: GDScript::reload (res://spawner.gd:6)
ERROR: Failed to load script "res://spawner.gd" with error "Parse error".
Godot raises it wherever the grammar expects a type: after the colon in var target: Enemy, in parameter and return types, inside Array[Enemy], after as, and on current versions after is. Three neighbouring messages come from the same lookup failing in a different position:
| Message | Where the name was used |
|---|---|
Could not find base class "KinematicBody2D". | On the extends line |
Identifier "Enemy" not declared in the current scope. | As a value, for example Enemy.new() |
Could not parse global class "Enemy" from "res://enemy.gd". | Anywhere; the class is registered but its own script has an error |
The causes below apply to the first two as well. The third sends you to the other file: open the script it names and fix the error there first. The value form has its own write-up in the “Identifier not found” guide.
What causes it
- A Godot 3 class name.
KinematicBody2D,Spatial,Sprite,PoolStringArrayand many others were renamed in Godot 4. Tutorials and copied snippets are the usual carriers. - The script that defines the type has no
class_name. A file calledenemy.gddoes not create a type calledEnemy. Only aclass_name Enemyline does. - A typo or wrong capitalisation. Type names are case-sensitive:
vector2,string,Int,Bool,Characterbody2DandIntegerall fail. The primitives are lowercase (int,float,bool) and everything else is capitalised (String,Vector2,Array). - The global class list was never built, or is stale. A fresh clone run from the command line or on CI has no
.godotfolder, so no script class is registered yet. Files renamed or added outside the editor leave the list out of date until Godot rescans. - An inner class or enum named without its owner.
Statsdeclared insideplayer.gdisPlayer.Statsfrom any other script. - An addon, GDExtension or C# class that is not registered. The addon folder is missing from the checkout, the extension’s library failed to load for your platform, the name was registered with
add_custom_type()(an editor label, not a GDScript type), or a C# class lacks the[GlobalClass]attribute. - A script in a pack loaded at runtime. Global classes defined only inside a pack loaded with
ProjectSettings.load_resource_pack()are a known weak spot, because the class list comes from the main project. This one is rare and only bites games with mods or downloadable packs.
How to find which cause is yours
- Press F1 and search the built-in help for the name. If an engine class exists with that spelling, the name is fine and something else is hiding it. If nothing comes up, it is either a Godot 3 name (check the table below), a typo, or one of your own classes.
- Use Search > Find in Files for
class_name Enemy. No result means cause 2. A result means the type exists, so open that script and look for an error marker in it. - Open
.godot/global_script_class_cache.cfgin a text editor. It is the list Godot reads at startup, one entry per registered class with its name, base, language and path. If your class is not in it, Godot has not registered it, whatever the script says. - Check the Output panel from editor startup for errors about an extension or plugin failing to load.
Fix 1: replace Godot 3 class names
| Godot 3 | Godot 4 |
|---|---|
KinematicBody2D / KinematicBody | CharacterBody2D / CharacterBody3D |
Spatial | Node3D |
Sprite / AnimatedSprite | Sprite2D / AnimatedSprite2D |
Area, RigidBody, StaticBody, CollisionShape | Area3D, RigidBody3D, StaticBody3D, CollisionShape3D |
Camera, MeshInstance, RayCast | Camera3D, MeshInstance3D, RayCast3D |
Position2D / Position3D | Marker2D / Marker3D |
Particles2D / Particles | GPUParticles2D / GPUParticles3D |
VisibilityNotifier2D | VisibleOnScreenNotifier2D |
Reference | RefCounted |
PoolStringArray, PoolByteArray, PoolVector2Array, PoolVector3Array, PoolColorArray | PackedStringArray, PackedByteArray, PackedVector2Array, PackedVector3Array, PackedColorArray |
PoolIntArray / PoolRealArray | PackedInt32Array / PackedFloat32Array (64-bit versions also exist) |
Transform / Quat | Transform3D / Quaternion |
SpatialMaterial | StandardMaterial3D |
StreamTexture | CompressedTexture2D |
File / Directory | FileAccess / DirAccess (the API changed too, not only the name) |
YSort | Removed. Turn on y_sort_enabled on a Node2D |
The pattern for 3D is consistent: nearly every node that had no suffix gained 3D. Renaming the type is only the first step, because members changed with it. CharacterBody2D has a built-in velocity and a move_and_slide() that takes no arguments, which is the next error you will meet: “Too many arguments for call”. Renamed constants on classes that kept their name are listed in the “Cannot find member in base” guide.
Fix 2: register your class with class_name
The broken pair:
# enemy.gd
extends CharacterBody2D
var health := 30
# spawner.gd
extends Node2D
var boss: Enemy # Could not find type "Enemy" in the current scope.
Add the registration to the script that defines the type and save it:
# enemy.gd
class_name Enemy
extends CharacterBody2D
var health := 30
The name is global to the project, so it must be unique, and it must not match an engine class or an autoload. Godot registers it when the editor scans the file. If you write code in an external editor, switch back to the Godot window so the scan runs; until then the class does not exist as far as other scripts are concerned.
Fix 3: get the type from preload instead
You do not need a global name to use a script as a type. A constant that holds the script works in every position a class name does:
extends Node2D
const Enemy = preload("res://enemies/enemy.gd")
var boss: Enemy
var wave: Array[Enemy] = []
func spawn() -> Enemy:
var e := Enemy.new()
add_child(e)
wave.append(e)
return e
This is the right choice for addon code that should not put names into the user’s global namespace, for scripts in packs loaded at runtime, and for anything that must work before the class list exists. The cost is one line per script that uses the type, and a path to keep correct when files move.
Fix 4: name inner classes through their owner
# player.gd
class_name Player
extends CharacterBody2D
class Stats:
var hp := 10
enum State { IDLE, RUN }
# hud.gd
extends Control
# var stats: Stats error: Stats is not visible here
var stats: Player.Stats
var shown_state: Player.State
Inside player.gd the short names work. Everywhere else the path starts at the owning class, or at a preload constant for that script.
Fix 5: rebuild the global class list
Try these in order, stopping when the error clears:
- Save the script that declares the class, then Project > Reload Current Project. This rescans the file system and rewrites the class list.
- On a build server or a fresh clone, import the project before running anything else. Godot 4.3 and later have a flag for it:
godot --headless --path . --import. On earlier 4.x versions usegodot --headless --path . --editor --quit; some projects need that command run twice before every class is registered. - As a last resort, close the editor and delete the
.godotfolder. Everything in it is generated, so nothing you authored is lost, but there is a real cost: every asset is reimported on the next launch (minutes on a large project), the shader cache is rebuilt, and per-project editor state such as open scenes and script tabs is forgotten. Do not do this as a first step.
Fix 6: addons, GDExtension and C#
For an addon, confirm the addons/ folder is really in the project and not excluded by .gitignore. Scripts in it that use class_name register like any other script. Names an addon adds with add_custom_type() appear in the Create Node dialog only; they cannot be used as type hints, so use the script’s class_name or a preload constant.
GDExtension classes are engine classes that exist only while the library is loaded. If the library for your platform or architecture is missing, every type hint that names one of its classes fails with this error. The load failure is reported in the Output panel when the editor starts, so fix that message and this one disappears.
A C# class becomes a global class when it carries the [GlobalClass] attribute (Godot 4.1 and later) and the C# project has been built. If your version still rejects it as a GDScript type hint, type the variable as the engine base class (Node, Resource) and call its methods without a static type.
How to confirm the fix
The error marker disappears when the script is saved. Check the other direction too: every script that uses the type must compile, and they only report errors when opened or loaded, so run the scenes that use them. For a custom class that extends Node, the Create New Node dialog is a quick registry check, because registered script classes are listed there by name. If CI was the place it failed, the test is a clean checkout with no .godot folder, the import command, then your export or test command.
When players see it
Normally this error never leaves the editor. The exception is a script that reaches a player’s machine unparsed: one in a mod or downloadable pack, or one in an export you did not run before shipping. The script then fails to load, the parse error goes to the engine’s log, and the node it was attached to quietly does nothing. Bugnet’s Godot SDK reads that log file for its automatic error capture, so with File Logging enabled (off by default on mobile exports) the failure can arrive on your dashboard with the platform, OS and game version, stacked with every other occurrence of the same title. It cannot catch what happens before the engine starts logging, and it does not replace running each exported build once. See capturing script errors in an exported game for what the log contains.
Related guides
- How to Fix “Parser Error: Identifier not found” in Godot
- How to Fix “Cannot find member in base” in Godot 4
- How to Fix “Too few arguments for call” and “Too many arguments for call” in Godot 4
- How to Fix “Function not found in base self” in Godot 4
- How to Fix Godot Resources Failing to Load After Cloning a Project (.godot/imported Missing)
Frequently asked questions
What does Could not find type in the current scope mean in Godot 4?
A type hint, cast or type test uses a name that is not a built-in type, an engine class, a class registered with class_name, or something declared in the current script. GDScript cannot parse the script until the name resolves.
Why does Godot 4 not recognise KinematicBody2D?
KinematicBody2D was renamed to CharacterBody2D in Godot 4, and its movement API changed with it: velocity is now a built-in property and move_and_slide takes no arguments. Replace the type name, then update the calls.
Do I need class_name to use my script as a type?
No. class_name registers a global name, which is convenient, but you can also load the script into a constant with preload and use that constant as the type in variable, parameter and return type hints.
Is it safe to delete the .godot folder?
Yes, with the editor closed. The folder holds generated data: imported assets, caches and editor state. Godot rebuilds it on the next launch, which means reimporting every asset and losing open tabs and layout, so try reloading the project first.
Why does the error only happen on CI or after cloning the project?
The .godot folder is not committed, so a fresh checkout has no global class list. Run an import pass first, using the import flag in Godot 4.3 or later, so the editor scans the scripts and registers every class_name before your tests or export run.
A file name is not a type. If Find in Files shows no class_name line for the name in the error, no amount of cache clearing will make it resolve.