GDScript Parser Error: "Unexpected identifier 'async' in Godot 4.1.1 Stable

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:

  1. async/await syntax should be fully supported in Godot 4.0 and later.
  2. As a test, when I tried replacing await get_tree().process_frame with the old Godot 3 syntax yield(get_tree(), "process_frame"), I correctly received the error Parse Error: "yield" was removed in Godot 4. Use "await" instead. This confirms the engine is running in Godot 4 mode and recognizes that yield is outdated.
  3. 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 using async/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!

Where in the documentation did you find this async keyword?

I’m pretty sure async is a C# keyword and not defined anywhere in GDScript. What happens if you run your code without the keyword?

1 Like

Here is the list of all keywords. async is not a keyword. You don’t need to use any special keywords in order to use await in a function. Awaiting a process frame will work correctly.

1 Like

Thanks! That was exactly the problem. Removing async fixed it. Really appreciate the clarification, it’s a great help for my GDScript learning process! :grinning:

1 Like