-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Illegal recursion allowed through PackedScene #84037
Comments
note for #80877 |
Note that I would actually like this to be allowed. My use-case is for example defining "Item" resources. These Items can appear in the shop, and when the user purchases them they instantiate the referenced PackedScene. I want the PackedScene to easily know which Item it belonged to, therefore I want the script associated with it to also reference back to the same resource. In other words, the shop has a list of ItemResources which reference PackedScenes. These PackedScenes (which are ingame representations of the purchased item) would like to reference back to the same ItemResource to know what data they are supposed to represent. |
I have a simpler case where I want to link doors/portals in two scenes by selecting map resource they're supposed to load. They're bidirectional and shown in the inspector which causes the same issue. So having just a normal Node2D which The editor knows the resource isn't broken and if the first scene is already loaded I can connect them, so I'm guessing fixing this likely requires resources to be loaded without recursively resolving them by first loading all linked resources and then connecting the graph as a subsequent step. As a workaround I'm using file names and formatting those into a cached This makes me also think that maybe some |
There is a proposal discussing introducing an Exported WeakReference that would theoretically solve this issue. Unfortunately it doesn't seem to be gaining much traction. I've posted a temporary non-ideal solution on that thread. |
Godot version
v4.1.2.stable.official [399c9dc]
System information
Godot v4.1.2.stable - Windows 10.0.22621 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3090 Ti (NVIDIA; 30.0.15.1216) - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)
Issue description
When you create a Resource that
@export
a variable, it will not allow a circular reference through other Resources.However, you can circumvent this and break Godot by creating the circular reference through a PackedScene such that the structure looks like the following:
ExampleResource:
@export my_scene: PackedScene
MyScene
@export my_resource: ExampleResource
i.e.
ExampleResource -> MyScene -> ExampleResource
You can save and run the project, but "MyScene" thinks that my_resource is null even if it is set in the editor. When you exit the project and try to re-open it, you get the following error:
From this point, you can no longer open MyScene or ExampleResource.
Steps to reproduce
Resource
(e.g. MyResource)Minimal reproduction project
ResourceRecursion.zip
The text was updated successfully, but these errors were encountered: