Hey guys

I've got some custom Resource class. It is used to hold the data for some custom editor property. Everything is working as expected in the inspector, and when there is only one instance of the scene in the level.

Now let's say I make a scene using that property. I set up things in the inspector, and then add a bunch of instances to the level. I get unexpected behavior because the resource class behind that property is shared between instances. How can I make it local through code? I did search and found resource_local_to_scene. But it doesn't seem to be working.

EDIT: To be more specific, there is a function inside the custom Resource class which I'm connecting to some signal of some other resource. The main problem is this: when there are multiple instances, the resource containing the function is shared and only one function is connected to the signal. If I emit the signal, only one instance will call the function and the rest will ignore it because I have:

if ReuseLogicNexus.global_signal_list.has_signal(global_signal.signal_name):
ReuseLogicNexus.global_signal_list.emit_signal(global_signal.signal_name, data)

This code only works once, because it's only ONE resource shared between all the instances.

  • xyz replied to this.
  • I got it. I did nothing wrong. This is a known issue in Godot:

    https://github.com/godotengine/godot/issues/71243

    I've been storing the resources in an array, and that's why the resource_local_to_scene = true did not work. Based on the solution from Calyad I fixed my problem. Here's his solution:

    So here is my stupid bloody fix, now that I know about this... "feature."

    Make two Array variables. Name one the thing you like ("Powers" or "Effects" or whatever), and name the other one similarly ("FakePowers" or "FakeEffects").

    Export the Fake array, and make it the Array you actually want. Pretend for the moment that there is no bug.

    When you load the node or instantiate it, make a recursive "duplicate(true) / resource_local_to_scene = true" function to copy all the resources from the Fake version of the array to the real version, which is not exported, and therefore works.

    Have a cookie and seek out a hug. This has been a rough time for all involved.

    while-free- Your code will need to reconnect the signal for each instance on startup. Although I'm not sure having resources sending or receiving signals is a wise design choice.

      xyz It is connecting them in the ready function on startup. The signals do work correctly.

      Actually I just created a minimal test project, and setting resource_local_to_scene to true in the _init function of the Resource class does fix the problem.

      But for some reason it's not fixing it in my actual project. I'll examine a bit more and will make a new post. The actual project is my addon:

      https://github.com/whilefree/ReuseLogic-Nexus

      And if I don't fix this problem months of hard work will get in serious danger.... 😐

      • xyz replied to this.

        while-free- resource_local_to_scene is only used when a resource is in a scene that gets instantiated via code. In that case the resource with will be duplicated and the duplicate will be assigned to the instantiated scene. Depending on what your signals are doing you might want to reconnect upon instantiation. Again, signaling resources are technically valid but my spider-sense is telling me it's asking for trouble.

          xyz Does this mean that resource_local_to_scene won't work if we drag and drop the scene in the node hierarchy?

          And what kind of trouble is your spider-sense talking about?

          • xyz replied to this.

            while-free- Does this mean that resource_local_to_scene won't work if we drag and drop the scene in the node hierarchy?

            It should work.

            while-free- And what kind of trouble is your spider-sense talking about?

            It just doesn't sound right from the design standpoint that a resource should send signals. It may be a sign to start thinking about possible alternatives in your system design.

              xyz The resource is used in such a design pattern:

              I'm reimplementing my Unity solution for Godot. Just in case you are curious...

              • xyz replied to this.

                kuligs2 its about unity garbage

                Applying Unity "logic" in Godot often ends in trouble 😃

                  xyz We'll see 😉

                  For now the question is why resource_local_to_scene is not working in the addon project. I'll report my investigation if I find anything new.

                  • xyz replied to this.

                    while-free- Make a minimal project that reproduces it and you'll get the answer.

                    5 days later

                    I got it. I did nothing wrong. This is a known issue in Godot:

                    https://github.com/godotengine/godot/issues/71243

                    I've been storing the resources in an array, and that's why the resource_local_to_scene = true did not work. Based on the solution from Calyad I fixed my problem. Here's his solution:

                    So here is my stupid bloody fix, now that I know about this... "feature."

                    Make two Array variables. Name one the thing you like ("Powers" or "Effects" or whatever), and name the other one similarly ("FakePowers" or "FakeEffects").

                    Export the Fake array, and make it the Array you actually want. Pretend for the moment that there is no bug.

                    When you load the node or instantiate it, make a recursive "duplicate(true) / resource_local_to_scene = true" function to copy all the resources from the Fake version of the array to the real version, which is not exported, and therefore works.

                    Have a cookie and seek out a hug. This has been a rough time for all involved.

                    • xyz replied to this.

                      while-free- I've been storing the resources in an array

                      You should have mentioned that in your question 😉

                        xyz Not really, it makes absolutely no sense to "ignore" the resource_local_to_scene for items in an array. It's a several years old "bug" on Godot side.

                        But this won't make me stop loving Godot. There's always a work-around for anything, isn't it? 😉

                        • xyz replied to this.

                          xyz I searched a bit more and there were people saying it's not fixed. But I didn't check it out myself; I want to keep backward compatibility, so I used the work-around solution. If you've checked it out for yourself please let us know.