Hi everyone,
I’m encountering a strange GDScript parser error in my project and I’m hoping someone might have seen this before or have some ideas.
Godot Version: I am using Godot v4.1.1.stable.official [49a5bc7b6]. I also tried updating to a recent development build 4.5-dev2 but the issue persists.
The Problem:
In one of my GDScript files (attached to a PanelContainer
), I need to wait for one frame using await
. To do this, I declare a function using the async keyword:
# Example structure causing the error
extends PanelContainer
# ... other code ...
async func my_async_function():
# ... some code ...
await get_tree().process_frame
# ... more code ...
# ... other code ...
However, the GDScript parser consistently throws the following error, pointing directly at the async
keyword:
Parse Error: Unexpected identifier 'async' in class body.
Why it’s confusing:
async
/await
syntax should be fully supported in Godot 4.0 and later.- As a test, when I tried replacing
await get_tree().process_frame
with the old Godot 3 syntaxyield(get_tree(), "process_frame")
, I correctly received the errorParse Error: "yield" was removed in Godot 4. Use "await" instead.
This confirms the engine is running in Godot 4 mode and recognizes thatyield
is outdated. - In a different debugging scenario involving input handling in another script, the parser correctly identified unreachable code after a
return
statement (UNREACHABLE_CODE
warning), proving that the parser is generally working and understanding code flow correctly in other parts of the project.
Troubleshooting Steps Taken:
- Meticulously checked for syntax errors, typos, or invisible characters around the
async func
line. - Verified indentation.
- Tried simplifying the function body.
- Tested on a newer development build (e.g., 4.5 dev2).
- Confirmed the script file encoding is UTF-8.
- Implemented a successful workaround using
get_tree().create_timer(0.0, ...)
and signals, which achieves the desired one-frame delay without usingasync/await
.
Despite the workaround, I’m concerned about why the standard async
keyword is failing to parse in my specific setup, even though the Godot version supports it and other parts of the parser seem functional.
Has anyone encountered a similar persistent parser error specifically with the async keyword on Godot 4.1+? Any ideas what subtle project setting, environment issue, or hidden syntax problem could cause this? Could it be a very specific, rare bug?
Thanks for any insights!