# Unexpected identifier "…" in class body in Godot 4

A statement is written at the top level of the script, outside any function, where only declarations are allowed. print("hello") under extends Node fails to parse with Unexpected identifier "print" in class body. Move it into a function such as _ready(), or indent it under the function it belongs to.

Source: https://flockbay.com/godot/unexpected-identifier-in-class-body/ · Updated 2026-10-30

## What Godot is checking

At class level GDScript accepts declarations only: extends, class_name, var, const, signal, enum, func, class and annotations. A call, an assignment or an if there is not a declaration, and the parser stops at its first token.

The usual cause is indentation: a line meant to be inside a function lost its indent and fell out to class level.

## Reproduce it

A print() written at class level.

```
extends Node

print("hello")

func _ready() -> void:
	pass

```

## What Godot 4.7.2 prints

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

SCRIPT ERROR: Parse Error: Unexpected identifier "print" in class body.
   at: GDScript::reload (res://answers/unexpected-identifier-in-class-body/repro.gd:3)
ERROR: Failed to load script "res://answers/unexpected-identifier-in-class-body/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)
```

## Fix it

The statement inside _ready(), and a member variable initialised at class level, which is allowed.

```
extends Node

var greeting := "hello"

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

```

## What the fixed script prints

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

hello
```

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

```
My Godot 4 project prints this error: "Parse Error: Unexpected identifier "print" in class body.". Find where it comes from and fix it. A statement is written at the top level of the script, outside any function, where only declarations are allowed. print("hello") under extends Node fails to parse with Unexpected identifier "print" in class body. Move it into a function such as _ready(), or indent it under the function it belongs to. Then run the game headless and check that Godot's output no longer shows it.
```

## 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_parser.cpp line 1215, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_parser.cpp#L1215).

## Questions

### Can a var at class level call a function?

Yes, in its initialiser: var start_time := Time.get_ticks_msec() is a declaration, so it is allowed.

### What does the wording "Unexpected Identifier" in older posts mean?

The same check. Godot 4.7.2 names the token: Unexpected identifier "print" in class body.

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: [Does Godot use Python? No: GDScript looks like Python, and here is where it is not](/godot/does-godot-use-python/), [Expected indented block after function declaration in Godot 4](/godot/expected-indented-block-after-function-declaration/), [Expected end of statement after variable declaration, found "Identifier" instead in Godot 4](/godot/expected-end-of-statement-after-variable-declaration/), [Used tab character for indentation instead of space as used before in the file in Godot 4](/godot/used-tab-character-for-indentation-instead-of-space/), [Every verified Godot 4 answer](/godot/), [How do I see Godot’s output and errors in Flockbay?](/docs/how-do-i-see-godots-output-in-flockbay/)
