Skip to content

How to get the class name of a node in Godot 4: get_class() and get_global_name()

By Eduardo Orellana · Updated

node.get_class() returns the engine class, such as "Node2D". For the class_name of the node's script, use node.get_script().get_global_name(). To test a type, use is: node is Node2D. There is no class_name property: node.class_name stops with Invalid access to property or key 'class_name' on a base object of type 'Node2D'.

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

class_name is a keyword that declares a script's global name, not a property of objects. Reading it as a property looks for a property of that name and fails.

get_class() always returns the native class the object was created as. A script attached to it does not change that; Script.get_global_name() returns the script's class_name, or an empty name when it has none.

More on this: The "export" keyword was removed in Godot 4: every export(...) and its @export annotation

Reproduce it

A Node2D asked for a class_name property.

GDScript
extends Node

func _ready() -> void:
	var sprite = Node2D.new()
	add_child(sprite)
	print(sprite.class_name)
	print("after")

What Godot 4.7.2 prints

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

SCRIPT ERROR: Invalid access to property or key 'class_name' on a base object of type 'Node2D'.
   at: _ready (res://answers/how-to-get-the-class-name-of-a-node-in-godot-4/repro.gd:6)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/how-to-get-the-class-name-of-a-node-in-godot-4/repro.gd:6)

Fix it

get_class() for the engine class, is for a type test, and the script's own name.

GDScript
extends Node

func _ready() -> void:
	var sprite = Node2D.new()
	add_child(sprite)
	print(sprite.get_class())
	print(sprite is CanvasItem)
	print(get_class(), ", script: ", get_script().resource_path.get_file())
	print("global name: '", get_script().get_global_name(), "'")

What the fixed script prints

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

Node2D
true
Node, script: fix.gd
global name: ''

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.

More on this: The "onready" keyword was removed in Godot 4: use @onready

Prompt
How to get the class name of a node in Godot 4: get_class() and get_global_name() node.get_class() returns the engine class, such as "Node2D". For the class_name of the node's script, use node.get_script().get_global_name(). To test a type, use is: node is Node2D. There is no class_name property: node.class_name stops with Invalid access to property or key 'class_name' on a base object of type 'Node2D'. Where this calls for a change in my Godot 4 project, make it, then run the game headless and check Godot's output for errors.

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_vm.cpp line 1128, the message, Object.get_class in the class reference, Script.get_global_name in the class reference.

Questions

How do I check a node is a class I wrote?
Give its script a class_name, then node is Enemy. is works with script classes the same as engine classes.
What does is_class() do?
It tests the engine class by name and its parents: node.is_class("CanvasItem"). It ignores scripts.

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

Download Flockbay free