Onready unexpected identifier

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tomasantunes

I was hoping to use the onready keyword to to load a variable but I get an error that says:

SCRIPT ERROR: Parse Error: Unexpected "Identifier" in class body.

Here is the code:
onready var muzzle = $Muzzle

Where did you write this? Show the rest of the script.

kidscancode | 2021-06-05 16:36

I don’t see any problem with that script. Indeed, if I paste it into Godot, it shows no errors.

kidscancode | 2021-06-05 17:04

I get an error on line 6. Could it be the version?

tomasantunes | 2021-06-05 18:02

:bust_in_silhouette: Reply From: kidscancode

I just saw that you’re using 4.0. You do realize that 4.0 is not even alpha stage yet?

You should only be using 4.0 if you are a developer who is working on it, or if you are testing and helping to find bugs/issues for those developers. Many things don’t work right now, and many others have changed from 3.x in ways that are not yet documented.

If you want to try and help with 4.0, you will need to follow the issues and discussions on Github, where you will find what has been changed. For example, GDScript has been changed a great deal, including many keywords becoming annotations, such as onready. Some of the changes are summarized here:

Again, I can’t recommend this more strongly: If you’re a beginner, you should not be using 4.0.

Hi! I’m bumping this because Godot 4.0 just entered alpha and I’m bumping into the same issue

Tadaboody | 2022-01-26 00:12

Again, because we’re only in alpha stage a lot of the documentation is not yet complete (most of us won’t really start writing docs until there’s a feature freeze).

That said, the issue here is that “onready” is now an annotation and the line above would be written

@onready var muzzle = $Muzzle

While the docs are not yet complete, there have been some updates to the GDScript doc that cover many of these new features:

GDScript reference — Godot Engine (latest) documentation in English

kidscancode | 2022-01-26 00:26

Over a year later with godot 4’s actual release and this is still the recommended answer…

Honestly, not actually answering the question and instead just telling them not to use the software is bad form, especially when your forum post is going to exist long into the future and be indexed on google for all the people looking for help down the line.

tiggerbiggo | 2023-03-05 14:45

:bust_in_silhouette: Reply From: Calinou

The onready keyword was replaced by the @onready annotation in Godot 4.0.

1 Like

Falto o “@” no “@onready