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

Circular dependency causes resources to be missing on export #77007

Open
RobertSzaszak opened this issue May 12, 2023 · 37 comments
Open

Circular dependency causes resources to be missing on export #77007

RobertSzaszak opened this issue May 12, 2023 · 37 comments

Comments

@RobertSzaszak
Copy link

Godot version

4.0 Stable

System information

Windows 10

Issue description

When exporting the project as a Windows executable, the application throws the following error.

Make sure resources have been imported by opening the project in the editor at least once.

Steps to reproduce

Export project as Windows Desktop (Runnable)
Run the application.

Minimal reproduction project

N/A

@RobertSzaszak
Copy link
Author

Same error when running the project from the editor in version 4.02.

Make sure resources have been imported by opening the project in the editor at least once.
  <C++ Error>    Condition "found" is true. Returning: Ref<Resource>()
  <C++ Source>   core/io/resource_loader.cpp:222 @ _load()`

@hunterkepley
Copy link
Contributor

My experience with this bug was exporting from Mac/Linux. Exports from Windows always worked for some reason.

Issue resolved randomly after a couple days. I tried reimporting objects that were error’d, but no luck. I also tried restarting Godot, re cloning my repo, restarting my pc, building from a Github Actions pipeline, and a couple other things. Builds just only worked on Windows.

I tried Godot 4.01, 4.02, and 4.1.dev1 — none of them fixed the issue. No idea how it resolved.

@hunterkepley
Copy link
Contributor

hunterkepley commented May 12, 2023

To add on, my game could export from all 4 ways described in my first comment originally, then it stopped working one day out of nowhere..

@Calinou
Copy link
Member

Calinou commented May 12, 2023

@RobertSzaszak @hunterkepley Please upload a minimal reproduction project to make this easier to troubleshoot.

@hunterkepley
Copy link
Contributor

I will look through my commits to find one, but it'll take some time

@RobertSzaszak
Copy link
Author

@Calinou Hi, How do I upload a minimal reproduction project? My game is quite big already. Shall I try to make it smaller and create a new repo for it? The issue seems to be with the load_threaded request function in my case.

@Zireael07
Copy link
Contributor

Minimal project is literally what it says. Create the smallest project you can that has the problem.

@hunterkepley
Copy link
Contributor

hunterkepley commented May 21, 2023

I am unable to recreate this issue with a project, it seems to happen at random. Currently my project is unable to build on OSX, but builds work from my automated pipeline on GitHub (linux) and my windows desktop. This was not the case last week.

I could provide my game with a lot of the code removed, if that would suffice, it just wouldn't be "minimal".

@hunterkepley
Copy link
Contributor

hunterkepley commented May 21, 2023

reu broken for github.zip
Moderator edit: Link removed for security, as the MRP contains secret credentials.

I removed all of the important code from my game such as rollback, server reconciliation, etc. As well as skipped the lobby and removed proprietary models I own

I have, however, included the export presets

All you need to do is export from OSX, (try a .dmg on a Mac first) start the game, press "Host" on the bottom left, and it should have a grey screen and spit out a ton of errors if ran from a terminal

Hope this helps

@RobertSzaszak
Copy link
Author

Seems like it works in version 4.0.3. You can close the issue.

@hunterkepley
Copy link
Contributor

   at: load (core/io/resource_format_binary.cpp:696)
ERROR: Failed loading resource: res://.godot/exported/133200997/export-ac4b7ec5c7c6a50838ddcd1f4e057820-candy_placer.scn. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:223)
ERROR: Can't load dependency: res://game/objects/candy_placer.tscn.
   at: load (core/io/resource_format_binary.cpp:696)
ERROR: Failed loading resource: res://.godot/exported/133200997/export-ccb27609e01d6460664dd431ed388159-bedroom.scn. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:223)
ERROR: Can't load dependency: res://game/levels/bedroom/bedroom.tscn.
   at: load (core/io/resource_format_binary.cpp:696)
ERROR: Failed loading resource: res://.godot/exported/133200997/export-be6198c9d492642daf2a2b8a18326593-bedroom_level.scn. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:223)

Still exists for me, please do not close

@hunterkepley
Copy link
Contributor

reu broken for github.zip

MRP without credentials in it

@hunterkepley
Copy link
Contributor

hunterkepley commented May 22, 2023

Hopefully this can be fixed soon, I am currently having to work on the game on my MacBook, then export from my windows desktop to linux and Mac, then upload that to AWS/my MacBook :(

@Calinou
Copy link
Member

Calinou commented May 23, 2023

This could be due to a similar cause as #55711, or due to texture compression project settings if this is a 3D project that uses VRAM compression for any textures (as is done by default).

@cosmoddd
Copy link

cosmoddd commented May 31, 2023

Happening in my scene as well. Several materials referenced by .GLTFs are not able to be parsed because the textures can't be loaded. This results in entire meshes not loading because they can't find the textures to load on the materials I've linked in the .gltf importer.

E 0:00:11:0282 _parse_ext_resource: res://Resources/Characters/Guard/guard upper.tres:6 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Resources/Characters/Guard/guard_packed1_diffuse_r1.png
<C++ Source> scene/resources/resource_format_text.cpp:162 @ _parse_ext_resource()

E 0:00:11:0282 load: res://Resources/Characters/Guard/guard upper.tres:6 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Resources/Characters/Guard/guard_packed1_diffuse_r1.png
<C++ Source> scene/resources/resource_format_text.cpp:735 @ load()

The this happens specifically if I use the ResourceLoader.load_threaded_request command. I do this so I can have a loading bar. Also, it's not 100% consistent - sometimes textures do load, and for almost all my models, this isn't an issue, but for some big ones it is. No amount of re-importing, renaming, or changing whether it's loaded into VRAM seems to make a difference

@hunterkepley
Copy link
Contributor

hunterkepley commented Jun 1, 2023

yes, i should add, this all started after i moved all my files one by one using Godot's "Move To" functionality

ever since, no number of changes, reimports, etc has fixed the issue.

also my game is 3D

@ZhuangXiongfei
Copy link

v 4.0.3
I have this problem too. My case is some of the code gen xxx.tscn file can not load while this line of code in Android:
load("res://.godot/exported/xxx/export-yyy-zzz.scn").instantiate()

error info:
_load: Failed loading resource: Make sure resources have been imported by opening the project in the editor at least once.

@Calinou
Copy link
Member

Calinou commented Jun 6, 2023

My case is some of the code gen xxx.tscn file can not load while this line of code in Android:
load("res://.godot/exported/xxx/export-yyy-zzz.scn").instantiate()

You should not load() files directly in the res://.godot/ folder, as the structure will change when the project is exported.

@cosmoddd
Copy link

cosmoddd commented Jun 6, 2023

I was able to trace my issue and potentially solve it:

After troubleshooting, I found my version of the error occurred only with specific image files that were shared by multiple materials. For example, Guard_BLUE and Guard_RED both use the same texture in their materials: guard_packed1_diffuse_r1.png. When objects using or sharing those materials are loaded using ResourceLoader.load_threaded_request, the error is thrown. It even causes the mesh in question to disappear from the scene.

Reading in the docs, a particular piece of information became apparent - if a resource is already loaded, Godot will not load it again. So what I ended up doing was this:

  1. Use the Debug panel to trace where the offending texture is. In my case, it was guard_packed1_diffuse_r1.png.
  2. Right click on the texture and click "View Owners." This will show which materials and which scenes were using it.
  3. Find the texture in the Scene and right click -> "Make Unique." This makes a unique version of the texture that shouldn't conflict with the texture already loaded. Alternatively, you can reimport the object with NO embedded images and manually assign materials in Godot.
  4. If you can't find the texture or have a huge scene, I was able to find it by opening up the scene in text format in VsCode and searching via a string match.

This seems to have resolved my issues with this error. It may not apply to many of you, but it's useful information to know that resources, particularly textures, CANNOT be loaded more than once in a scene, unless explicitly marked to do so by making them "Unique". My suggestion would be to make this information part of the warning / error message, so users can know where and how to troubleshoot this.

@ZhuangXiongfei
Copy link

My case is some of the code gen xxx.tscn file can not load while this line of code in Android:
load("res://.godot/exported/xxx/export-yyy-zzz.scn").instantiate()

You should not load() files directly in the res://.godot/ folder, as the structure will change when the project is exported.

I read this path in the apk/assets/xxx.tscn.remap file

@mddizon
Copy link

mddizon commented Jul 9, 2023

For what it's worth I worked through this issue with my project.

The errors were pointing to the script property attached to the root node:

In game.tscn

[node name="Game" type="Node2D"]
script = ExtResource("1_3emra")

I removed the script = ... line, and then further above I removed the line with the matching id:
Also in game.tscn

[ext_resource type="Script" path="res://scripts/game.gd" id="1_3emra"]

After that I was able to load the scene, and the script was not attached. I was able to add it back, generating a new id and everything seems to work again. Hope this is helpful!

@infohub-gather
Copy link

infohub-gather commented Sep 1, 2023

I am currently finding these errors in a project coming over from 4.0.x versions of it. I did a fully new project import yet somehow these errors appeared in 4.1.x versions of Godot. If I have helpful information on probable causes of this problem I will report here.

@SimoneStarace
Copy link

SimoneStarace commented Sep 17, 2023

Good morning everyone.
I'm having the same issue of @RobertSzaszak
I have made a very basic 2d Top-Down game where there are 7 scenes.

  • One for the player
  • One for the end screen scene
  • Five for the levels.

Yesterday I was working on it without any issue, but this morning I'm having this issue.

The version of Godot I'm using is Stable 4.1.1.

@Calinou

Please upload a minimal reproduction project to make this easier to troubleshoot.

It is ok to link to my repository since I have published it?

@SimoneStarace
Copy link

SimoneStarace commented Sep 17, 2023

After digging for an hour on understanding why I was receiving this error on my project, the reason was in one of the scenes there was a weirdly missing reference to another scene.

In short my game is structured as follow:

  • On each level, once the player reaches the goal, the next scene is loaded.
  • In the last scene I have added a button that, when clicked, it brings the player to restart playing from the first level. This is where I was getting the error Make sure resources have been imported by opening the project in the editor at least once because, for some reason, Godot wasn't able to find the first scene.

To solve the problem I had to modify the scene file, manually by removing the missing reference of the scene.
Now all the scenes are loaded normally without issues.

Probably, this might not be the answer for Robert but it seems that this issue depends on how files are handled.

@Av0c
Copy link

Av0c commented Sep 29, 2023

Similar issue happened to my project. (Using Godot 4.1.1.stable.mono)

I have "sceneA", which has a script with an [Export] reference to "sceneB". Similarly, "sceneB" also has a script with a reference to "sceneA". This relationship caused the issue for me, but I don't know if it's the only thing that does.

On reloading of the project, such relationship breaks every scenes it was involved in, causing the error as in the original post. Furthermore, if other scenes have any reference (either by script, or nested in the tree) to scenes broken this way, those will break too. This has caused all but one of my scenes to break.

I managed to resolve it by editing the .tscn files and removing all PackedScene references, but I'm afraid to move forward with the project since the same thing could happen again anytime, in a bigger scale, and I wouldn't be able to notice it until the project is reloaded and everything breaks.

@aurumboros
Copy link

aurumboros commented Oct 3, 2023

Similar issue happened to my project. (Using Godot 4.1.1.stable.mono)

I have "sceneA", which has a script with an [Export] reference to "sceneB". Similarly, "sceneB" also has a script with a reference to "sceneA". This relationship caused the issue for me, but I don't know if it's the only thing that does.

On reloading of the project, such relationship breaks every scenes it was involved in, causing the error as in the original post. Furthermore, if other scenes have any reference (either by script, or nested in the tree) to scenes broken this way, those will break too. This has caused all but one of my scenes to break.

I managed to resolve it by editing the .tscn files and removing all PackedScene references, but I'm afraid to move forward with the project since the same thing could happen again anytime, in a bigger scale, and I wouldn't be able to notice it until the project is reloaded and everything breaks.

I've got exactly the same issue with a similar case where I use TP point to load a new map. For my test the A map tp to B and the B to A. My A scene was causing the trouble. I'm using @export too with PackedScene as type. Edit: with godot 4.1.1 as well.

@SimoneStarace
Copy link

I've got exactly the same issue with a similar case where I use TP point to load a new map. For my test the A map tp to B and the B to A. My A scene was causing the trouble. I'm using @export too with PackedScene as type. Edit: with godot 4.1.1 as well.

@aurumboros TP stands for? Anyway which node are you using for loading the levels because to me it was a problem with the node I used for loading the next level.

@aurumboros
Copy link

I've got exactly the same issue with a similar case where I use TP point to load a new map. For my test the A map tp to B and the B to A. My A scene was causing the trouble. I'm using @export too with PackedScene as type. Edit: with godot 4.1.1 as well.

@aurumboros TP stands for? Anyway which node are you using for loading the levels because to me it was a problem with the node I used for loading the next level.

Sry, TP stands for "Teleport".
To solve the issue -> I used a global dictionnary with some enums and the path to the scenes I want. I load the scene only when needed and it solves the issue.

In my previous setup, a "TP node" from a "scene A" referenced "scene B" thanks to @export Packed Scene with some coordinates to load the scene and teleport the player. Then in the "scene B" a node has a reference of the "scene A" with coordinates too. And the reference from A -> B and B -> A break the scenes until you remove the reference in the .tscn

@superherointj
Copy link

superherointj commented Oct 9, 2023

I'm also experiencing this issue, Godot 4.1.2. When:

godot4 --headless --export-release "Linux/X11" $out/bin/tank

Error:

ERROR: res://scenes/components/health_component.tscn:6 - Parse Error:
at: _parse_node_tag (scene/resources/resource_format_text.cpp:283)
ERROR: Failed loading resource: res://scenes/components/health_component.tscn. Make sure resources have been imported by opening the project in the editor at least once.
at: _load (core/io/resource_loader.cpp:273)

Reference also points to script. By removing script, error is gone. But I need the script...

Contents of health_component.tscn (which references script):

[gd_scene load_steps=2 format=3 uid="uid://dax2x4s2u7l4v"]
[ext_resource type="Script" path="res://scenes/components/health_component.gd" id="1_yvfi3"]
[node name="HealthComponent" type="Node"]
script = ExtResource("1_yvfi3")

I understand that this problem has to be replicated in a discrete project and isolated. [Will attempt to do so.]

@Chemiseblanc
Copy link

I've experienced this issue and have been able to semi-reliably recreate the error and recover from it.
Replication project here

@erinorina
Copy link

erinorina commented Nov 28, 2023

minimal reproduction project,

  • drop a png file in the executable folder,
  • ,create a TextureRect node and attach this script to it,
extends TextureRect

var new_material = ShaderMaterial.new()
var texture_path: StringName
var dir = DirAccess.open(OS.get_executable_path().get_base_dir())
var shader_material

func _ready():
	var shader = Shader.new()
	shader.code = """
		shader_type canvas_item;
		uniform sampler2D my_texture;

		void fragment() {
			COLOR = texture(my_texture, UV);
		}
	"""
 
	new_material.shader = shader
	self.material = new_material
	shader_material = self.material

	DirAccess.get_files_at(OS.get_executable_path().get_base_dir())
	preload_textures()

func preload_textures():
	if dir != null:
		dir.list_dir_begin()
		var files = []
		var file_name = dir.get_next()
		while file_name != "":
			if file_name.ends_with(".png"):
				files.append(file_name)
			file_name = dir.get_next()
		dir.list_dir_end()
		if files.size() > 0:
			texture_path = OS.get_executable_path().get_base_dir() + "/" + files[randi() % files.size()]
			var texture = ResourceLoader.load(texture_path)
			if texture:
				shader_material.set_shader_parameter("my_texture", texture)
			else:
				print("Failed to load texture:", texture_path)
		else:
			print("No PNG  files found in", OS.get_executable_path().get_base_dir())

# In editor error :
# E 0:00:00:0564   Control.gd:42 @ preload_textures(): No loader found for resource: /home/sd/Apps/1.png.
#   <C++ Error>    Method/function failed. Returning: Ref<Resource>()
#   <C++ Source>   core/io/resource_loader.cpp:281 @ _load()
#   <Stack Trace>  Control.gd:42 @ preload_textures()
#                  Control.gd:28 @ _ready()

#  in linux debug build :
# Godot Engine v4.1.3.stable.official.f06b6836a - https://godotengine.org
# OpenGL API 3.3.0 NVIDIA 525.125.06 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce RTX 3060
# 
# ERROR: No loader found for resource: /home/sd/Godot-4.1/Tests/cant_load_png/1.png.
#    at: _load (core/io/resource_loader.cpp:281)
# Failed to load texture:/home/sd/Godot-4.1/Tests/cant_load_png/1.png


@rob-williams
Copy link

I just encountered this error in my project and found the problem, at least for me.

TL;DR: A Resource referenced Script, and the code in that Script loaded the Resource referencing it. Circular dependency during GDScript parsing.

I had a custom Resource with a reference to a Script, i.e., a .gdscript file. For one of those resources, the Script it referenced called preload() with a path to the Resource referencing it. This created a circular dependency that broke GDScript parsing. Changing it to load(), so it loaded at runtime and not during parsing, did not resolve it - I had to remove the circular reference entirely.

Hopefully this helps others who encounter this. I'm not quite sure why a script referencing a Resource that references back to the script breaks parsing, at least with a runtime call to load().

@Eoin-ONeill-Yokai
Copy link
Contributor

Eoin-ONeill-Yokai commented Dec 20, 2023

I can confirm this issue on my end and @rob-williams is 100% right on the cause. #85922 doesn't solve this issue either, so it's still a problem.

Here's a quick example of a potential recursion issue:

class_name Character
extends CharacterBody2D


const JUMP_VELOCITY = -400.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var speed = 300.0


static func make(p_speed : float) -> Character:
	var pack_scene = preload("res://Character.tscn")
	var instance = pack_scene.instantiate()
	instance.speed = p_speed
	return instance

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var direction = Input.get_axis("ui_left", "ui_right")
	if direction:
		velocity.x = direction * speed
	else:
		velocity.x = move_toward(velocity.x, 0, speed)

	move_and_slide()

This is a simplified version of a issue I have had in a much larger project. Basically, the static func is defined as a shorthand constructor for quickly instantiating a scene with specific args. This script is attached to the root node, but the attachment point is likely unimportant. Notably, this flags an error at resource_format_text.cpp:284 which gives no user feedback but debugging found that it returned ERR_BUSY. I'm still digging around to determine which method down the chain is returning ERR_BUSY but I can at least provide a minimum reproduction project.

recursive_parse_error.zip

If we could, it would be nice to update the issue's title to reflect this recursion situation unless other potential causes can be determined. This is the only sure fire way I know to reproduce this bug -- and even then, there are occasions where it inexplicably works. This inconsistency, and the ERR_BUSY return, gives me the feeling that there's some threading issue at play here.

@charlespaivadev
Copy link

My case is some of the code gen xxx.tscn file can not load while this line of code in Android:
load("res://.godot/exported/xxx/export-yyy-zzz.scn").instantiate()

You should not load() files directly in the res://.godot/ folder, as the structure will change when the project is exported.

@Calinou, how I supposed to load() the files? I'm having this issue and I'm doing exactly what you said not to

@Calinou Calinou changed the title Make sure resources have been imported by opening the project in the editor at least once. Circular dependency causes resources to be missing on export Feb 8, 2024
@Calinou
Copy link
Member

Calinou commented Feb 8, 2024

@charlespaivadev You should load() the source resource instead of the imported file in res://.godot. Godot will perform the remap for you, so you don't actually need to know the file path in res://.godot.

@LeoZhang421
Copy link

Solved this problem by manually deleting the res://.godot/export and res://.godot/import folder and then reload the project (let godot generate a new one for you), don't know how it happened, checked and confirmed all the error paths actually exists in the .pck file, so I guess it should be some kind of loading issue

@hunterkepley
Copy link
Contributor

@LeoZhang421 +1 for the workaround, thank you

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