godotengine / godotengine/godot

Autoload scenes emit errors on initial import when referencing imported resources

Open
#89,879 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic:import
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### 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](https://github.com/godotengine/godot/files/14743952/imports-in-autoloads.zip)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce with the attached imports-in-autoloads.zip after deleting .godot, using the command-line or --headless --editor --quit. Start by reading scene/resources/compressed_texture.cpp and core/io/resource_loader.cpp, then trace when autoloads and resource importing run. Done means the first run no longer reports missing imported resources and my_autoload.gd does not receive a null resource.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.