godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.53k stars 21.26k forks source link

Autoload scenes emit errors on initial import when referencing imported resources #89879

Open mihe opened 8 months ago

mihe commented 8 months ago

Tested versions

Reproducible in: 4.3.dev [5d08c2631]

System information

Windows 11 (10.0.22631)

Issue description

When using an autoload scene that depends on pretty much any kind of imported resource you are more or less guaranteed to run into errors on the first run of the editor, or when running it through something like a CI build. These errors are usually along the lines of ERROR: Unable to open file: res://.godot/imported/[...], which seems to be due to the fact that autoloads are loaded before any resource importing has happened.

The errors in this particular MRP look like this:

ERROR: Unable to open file: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex.
   at: (scene\resources\compressed_texture.cpp:41)
Unable to open file: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex.
ERROR: Failed loading resource: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core\io\resource_loader.cpp:278)
Failed loading resource: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex. Make sure resources have been imported by opening the project in the editor at least once.
ERROR: Failed loading resource: res://icon.svg. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core\io\resource_loader.cpp:278)
Failed loading resource: res://icon.svg. Make sure resources have been imported by opening the project in the editor at least once.

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. Note how my_autoload.gd fails with Cannot call method 'get_size' on a null value.
  5. Load the MRP project from command-line again.
  6. Note that there are no errors this time.

Note that some of 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)

imports-in-autoloads.zip

mihe commented 8 months ago

Tangentially related to #77037 and #89399, in the sense that it's about autoloads and editor load ordering, but shouldn't (in my opinion) be considered a duplicate of either.