Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoload GDScript emit errors on initial import when referencing named/global classes #89399

Closed
mihe opened this issue Mar 11, 2024 · 2 comments

Comments

@mihe
Copy link
Contributor

mihe commented Mar 11, 2024

Tested versions

Reproducible in: 4.3.dev [f040a35]

System information

Windows 11 (10.0.22631)

Issue description

When using an autoload script which itself is relying on named/global (class_name) classes, you will encounter errors during the initial import that looks something like this:

SCRIPT ERROR: Parse Error: Identifier "MyGlobal" not declared in the current scope.
          at: GDScript::reload (res://my_autoload.gd:4)
res://my_autoload.gd:4 - Parse Error: Identifier "MyGlobal" not declared in the current scope.
ERROR: Failed to load script "res://my_autoload.gd" with error "Parse error".
   at: ResourceFormatLoaderGDScript::load (modules\gdscript\gdscript.cpp:2825)
modules\gdscript\gdscript.cpp:2825 - Failed to load script "res://my_autoload.gd" with error "Parse error". (User)
ERROR: Failed to create an autoload, script 'res://my_autoload.gd' does not inherit from 'Node'.
   at: (editor\editor_autoload_settings.cpp:424)
Failed to create an autoload, script 'res://my_autoload.gd' does not inherit from 'Node'.

The problem seems to stem from the fact that the list of global classes (global_script_class_cache.cfg) hasn't been created by the time autoload resources are loaded in the EditorAutoloadSettings constructor, which leads to any such references being undeclared identifiers.

Once this global_script_class_cache.cfg file has been created you won't get errors any longer when loading the project.

Steps to reproduce

  1. Delete any existing .godot folder (if loading the MRP again).
  2. Load the MRP project from command-line.
  3. Note the command-line (stderr) errors as shown in the issue description.
  4. Load the MRP project from command-line again.
  5. Note that there are no errors this time.

Note that these errors might not show up in the editor output log, as EditorLog hasn't been set up by the time they're emitted, so it's important to do this through command-line.

Also note that you can similarly reproduce these errors by running Godot with something like --headless --editor --quit, or even a command-line export, so long as you delete the .godot folder beforehand.

Minimal reproduction project (MRP)

globals-in-autoloads.zip

@adamscott
Copy link
Member

adamscott commented Mar 12, 2024

Relates to #77037. Not a duplicate, but relates to the same behavior (editor/game initialization).

@mihe
Copy link
Contributor Author

mihe commented Apr 22, 2024

It appears that this is a duplicate of #75388.

@mihe mihe closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants