Open robobun7 opened 1 year ago
IIRC cyclic scene references are NOT a supported case
Maybe we should improve the error message. We had many such reports.
I just spent hours debugging a problem that turned out to be this issue. It would be great if the error message stated where the script has been preloaded so it's easier to debug this kind of problem.
I just ran into this same issue, but it seems that the affected files become permanently broken. We need a way for a warning or error to happen, but be able to fix it. Someone does this by accident in a large game and it could become disastrous before they truly realize what has happened. Given we should all have our projects backed up, this is still problematic.
In my case, I was able to fix it by getting rid of a preload
statement in one of my scripts that ended up causing the circular dependency. It was super annoying, but I don't think the files are permanently broken
Yes you are correct. In some cases I later found if I reloaded the engine it fixed it at that point in time.
Godot Engine v4.2.dev3.official [013e8e3af]
I have been scratching my head at the same problem, and have had to manually edit the scene files to un-corrupt them once or twice. After some fiddling, I have found that setting the ResourceLoader.load cache to IGNORE :
var s = ResourceLoader.load(nextScene, "PackedScene",ResourceLoader.CACHE_MODE_IGNORE)
allows me to use one scene such as a "door" to load back and forth between levels.
full switch scene function (accepts a PackedScene.resource_path)
func _deferredSwitchScene(nextScene):
print(nextScene)
Signals.loadingStarted.emit()
currentScene.queue_free()
var s = ResourceLoader.load(nextScene, "PackedScene",ResourceLoader.CACHE_MODE_IGNORE)
currentScene = s.instantiate()
get_tree().root.add_child(currentScene)
get_tree().current_scene = currentScene
await get_tree().create_timer(1).timeout
Signals.loadingFinished.emit()
This does spit out an error everytime the next scene in the circular scene switcher loads:
E 0:00:00:0909 _parse_ext_resource: res://scenes/levels/puzzles/orangeBox/orangeBoxPuzzle.tscn:106 - Parse Error: [ext_resource] referenced non-existent resource at: res://scenes/levels/main.tscn
<C++ Source> scene/resources/resource_format_text.cpp:162 @ _parse_ext_resource()
E 0:00:03:0207 sceneSwitcher.gd:16 @ _deferredSwitchScene(): res://scenes/levels/main.tscn:91 - Parse Error: [ext_resource] referenced non-existent resource at: res://scenes/levels/puzzles/orangeBox/orangeBoxPuzzle.tscn
<C++ Source> scene/resources/resource_format_text.cpp:162 @ _parse_ext_resource()
<Stack Trace> sceneSwitcher.gd:16 @ _deferredSwitchScene()
E 0:00:20:0143 sceneSwitcher.gd:16 @ _deferredSwitchScene(): res://scenes/levels/puzzles/orangeBox/orangeBoxPuzzle.tscn:106 - Parse Error: [ext_resource] referenced non-existent resource at: res://scenes/levels/main.tscn
<C++ Source> scene/resources/resource_format_text.cpp:162 @ _parse_ext_resource()
<Stack Trace> sceneSwitcher.gd:16 @ _deferredSwitchScene()
and so on. I agree very wholeheartedly that while "circular dependencies" may not be supported, they are a very common landing spot for beginner and advanced game devs, as many game designs have the player switching back and forth between two areas / scenes.
seanluse41's workaround works until I close and reopen Godot, then my scenes get corrupted and I have to remove all the "ext_resource" lines and set them again in the editor. Is there any way to achieve this that doesn't cause corruption? Using a string path instead of PackedScene for the exported variables solves it, but it means I can't use drag and drop (I have to manually copy the node path) and I don't see the node preview in the editor.
You can use @export_file
. The variable will still be a String and you will be able to use drag and drop.
"Use load()
instead of preload()
"
Just came across this same issue. As said in another ticket (https://github.com/godotengine/godot/issues/77436) by the team staff: https://github.com/godotengine/godot/issues/77436#issuecomment-1561098873
Also refer to: https://github.com/godotengine/godot/pull/71004 https://github.com/godotengine/godot/issues/70985#issuecomment-1564326877
Are there any plans on fixing this yet? If not what are some simple flexible ways to implement scene switching?
change_scene_to_file(exported_scene_path)
, with exported_scene_path
being insusceptible to cyclic dependencies or moving the scene file.I was also able to find that the issue can be partially circumvented (at least in my case) by replacing my @export var...
with @export_file var...
and adjusting my code a little.
Godot version
4.0.2
System information
Windows 10
Issue description
I created a button that, when pressed, called change_scene_to_packed() with a PackedScene variable as the target. The variable is exported into the editor, where I can then drag and drop a scene into it for the button to change the scene to.
This works fine, the button changes the scene to the target scene. If the target scene also has another instance of the button in it linking to a third scene, that also works fine.
However, if one of the scenes links back to an earlier scene, it crashes and only produces an error in the console, not in the editor itself.
Here's the error when I have scene1 link to scene2, scene2 link to scene3, and scene3 link back to scene1:
When I tried saving the project and reloading it, I got a "Load Error" dialog with an empty message box and this error in both the console and the debugger:
The button in the last scene is also stripped of its target scene. This happens whether or not I run the project after assigning the variables in the editor.
If I use change_scene_to_file() and use a file path string instead of a PackedScene variable, the scene loop works fine. This only happens when using change_scene_to_packed() and a PackedScene variable.
Steps to reproduce
The minimal reproduction project contains a version with two scenes. If you use it, make sure you reassign the button's targetscene variable on the second scene to scene1.tscn since Godot empties it upon loading.
Minimal reproduction project
repro test both scenes.zip