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

Script removed from node upon preload scene in cyclic reference. #76641

Open
Tracked by #80877
saierXP opened this issue May 1, 2023 · 7 comments
Open
Tracked by #80877

Script removed from node upon preload scene in cyclic reference. #76641

saierXP opened this issue May 1, 2023 · 7 comments

Comments

@saierXP
Copy link

saierXP commented May 1, 2023

Godot version

4.0.3.rc1

System information

Windows Vulkan API 1.3.217 - Forward Mobile -AMD Radeon(TM) Vega 8 Graphics

Issue description

bullet.gd

extends Node2D

var player:Player

player.gd

class_name Player
extends Node

func _test():
	var bullet = preload('res://bullet.tscn')

When running the bullet.tscn scene, the following errors will be reported


ERROR: res://bullet.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://bullet.gd
   at: load (scene/resources/resource_format_text.cpp:490)
ERROR: Failed loading resource: res://bullet.tscn. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core/io/resource_loader.cpp:222)
ERROR: Another resource is loaded from path 'res://bullet.tscn' (possible cyclic resource inclusion).
   at: (core/io/resource.cpp:75)

The script will be lost after restarting the editor.

See video:

preload_scene_bug.mp4

BUG found from the PR(godotengine/godot-demo-projects#849) of Calinou in #75039
Other related issues:
I can reproduce the problem again from its MRP #74110.
I'm not sure if it's related to this, but there's some discussion in #68661.

Steps to reproduce

Maybe if you open the project, you will lose the bullet script, please make sure that the bullet is attached to the scene.

  1. Run the bullet scene.
  2. Restart the editor.
  3. The bullet.gd will miss.

Minimal reproduction project

preload_scene_cyclic.zip

@SeanRamey
Copy link

So, I have found out that the script will remain attached to the scene if you edit the player.gd script by changing the preload() to load(), saving it, then changing the load() to preload(), and saving again. Now close and reopen the project, it will still be attached. This does not remove the runtime errors, however.

@SeanRamey
Copy link

Actually, it seems that fix is only temporary? I started up my PC today and loaded it, and the script was detached again.

@Necronomicron
Copy link

Necronomicron commented May 19, 2023

Just encountered this.
v4.1.dev2.official [668cf3c]
preload() is what causing this in my case.
#64330

@heppocogne
Copy link
Contributor

One of the cause of this issue might be this code. Dependency error is detected here, but no errors are generated. As a result, script is set to null (=removed).

} else {
ResourceLoader::notify_dependency_error(local_path, path, type);
}

@heppocogne
Copy link
Contributor

Why does GDScriptAnalyzer permit cyclic references? Does GDSCript2.0 actually support it?

// Must load GDScript and PackedScenes separately to permit cyclic references
// as ResourceLoader::load() detect and reject those.

@Zireael07
Copy link
Contributor

@heppocogne Yes, GDScript 2.0 has a (limited) support for cyclic references

@LostNulide
Copy link

LostNulide commented Aug 29, 2023

So, I have found out that the script will remain attached to the scene if you edit the player.gd script by changing the preload() to load(), saving it, then changing the load() to preload(), and saving again. Now close and reopen the project, it will still be attached. This does not remove the runtime errors, however.

Had a similar issue where using load fixed the whole project.

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

8 participants