# 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'.

Source: https://flockbay.com/godot/how-to-get-the-class-name-of-a-node-in-godot-4/ · Updated 2026-10-30

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

## Reproduce it

A Node2D asked for a class_name property.

```
extends Node

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

```

## What Godot 4.7.2 prints

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

```
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

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

```
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](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1128), [Object.get_class in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Object.xml), [Script.get_global_name in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Script.xml).

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

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [Invalid access to property or key '…' on a base object of type 'Dictionary' in Godot 4](/godot/invalid-access-to-property-or-key-on-dictionary/), [Invalid assignment of property or key '…' with value of type '…' on a base object of type 'Node2D' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-node2d/), [Invalid cast: can't convert a non-object value to an object type in Godot 4](/godot/invalid-cast-cant-convert-a-non-object-value-to-an-object-type/), [Cannot find member "…" in base "…" in Godot 4](/godot/cannot-find-member-in-base/), [Every verified Godot 4 answer](/godot/), [How do I connect Claude Code to Godot?](/docs/how-do-i-connect-claude-code-to-godot/)
