0 votes

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

Godot version 4.0
in Engine by (20 points)

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

Here is the script: https://pastebin.com/UANXnwUH

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

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

2 Answers

+1 vote
Best answer

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.

by (21,712 points)
selected by

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

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:


+2 votes

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

by (12,649 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.