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

resource_local_to_scene not working in arrays. Still in 4.3 dev 5? #90597

Open
Iakl opened this issue Apr 12, 2024 · 6 comments
Open

resource_local_to_scene not working in arrays. Still in 4.3 dev 5? #90597

Iakl opened this issue Apr 12, 2024 · 6 comments

Comments

@Iakl
Copy link

Iakl commented Apr 12, 2024

Tested versions

  • Reproducible at least in Godot v4.2.1stable and Godot v4.3dev5

System information

Godot v4.3.dev5 - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1650 Ti with Max-Q Design (NVIDIA; 31.0.15.5186) - Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 Threads)

Issue description

Hi guys, I faced this problem and a quick search showed me that it was a bug already fixed in 4.3 dev 5, so I downloaded it but I still have the same issue. Is the bug still present or I'm doing something wrong?

Related Changelog entries:

Changelog for 4.3-dev3:

Fix recursive resource local to scene (array/dictionary properties on resources) ([GH-71578]

Changelog for 4.3-dev5:

Fix resource_local_to_scene in arrays and dictionaries ([GH-87268]

Steps to reproduce

1.- I created a resource file with some @export entries
2.- In my scene script I added a line like this:
@export var params: Array[ParamsResource] = []
3.- Then in the inspector I create the resources and for each element of the array, I mark it as local to scene.
4.- I run the game. The scene is not instantiated yet. I have to do it with a button
5.- When I instantiate the scene, in the _ready() I modify the attributes in one of the resources in the array.
6.- I instantiate then another scene of the same object and it already has the same modifications before the _ready() function do them.

Minimal reproduction project (MRP)

minimal.zip

I made this reproduction project that reproduces the problem, but not with the exact steps I described (which are from my game). Hope this does not confuse you.

@brno32
Copy link
Contributor

brno32 commented May 24, 2024

For what it's worth I was not able to reproduce this in my own C# project.

"Local to Scene" was not working for me in Godot 4.2 with Resources inside of an array.

I downloaded 4.3-dev6 and reopened the same project and now it's working.

public partial class Enemy : CharacterBody3D
{
    [Export] private Stat[] stats;
    // ...
}
using Godot;
using System;

public partial class EnemySpawner : Node
{
    [Export] public PackedScene enemyScene;

    public override void _Ready()
    {
        for (int i = 0; i < 4; i++)
        {
            Enemy enemy = enemyScene.Instantiate<Enemy>();
            enemyParty.AddChild(enemy);
        }
    }
}

On the Enemy scene, if I check "Local to Scene" in each of my Stat resources in my stats array, it seems to work.

@trickster721
Copy link

I reproduced this in v4.3.stable.official [77dcf97]. Created a scene with an attached script, which exports an array of resources, marked Local to Scene. When the scene is instantiated at runtime, the resource isn't duplicated. Works as expected when the scene is instantiated in the editor.

@trickster721
Copy link

Oh, wait, the resources aren't duplicated at runtime because exported Arrays aren't duplicated when instanced at runtime. So this would be a duplicate of #16478.

@pumpingGhost
Copy link

Had the same problem on 4.2.2. After upgrading to 4.3_stable, it now works as expected.

@trickster721
Copy link

@pumpingGhost Were you able to get Resources in an exported Array to duplicate when using instantiate() on a PackedScene in a script? Could you share the code you're using?

This issue is specifically with instantiating at runtime, in a script. It seems like there might be some confusion about whether the two PRs in 4.3 actually covered that.

@pumpingGhost
Copy link

@pumpingGhost Were you able to get Resources in an exported Array to duplicate when using instantiate() on a PackedScene in a script? Could you share the code you're using?

This issue is specifically with instantiating at runtime, in a script. It seems like there might be some confusion about whether the two PRs in 4.3 actually covered that.

No I had instantiated the scenes via the scenetree in another scene. So here's my setup:

  • Scene A has an exported Array of custom resource type and in the editor, a "default" resource is assigned with LocalToScene = true
  • Scene B's scenetree contains multiple instances of Scene A.

When launching the game, Godot applies new resources for each instance of Scene A within Scene B at runtime.

I haven't tested how it behaves when instantiating PackedScenes in code.

However I noticed some more issues with the resources within the editor. Resetting the resource of Scene A instances in the Scene B scenetree is very inconsistent, as sometimes it resets to a local resource of Scene B and sometimes it resets to the external resource of Scene A. I played around with this for over an hour now, but cannot figure out a pattern of how and when the resources are duplicated. It almost seems as if Scene B has local instances of the resource defined as subresource in the .tscn file, Godot takes that resource at runtime and if not, it falls back to a copy of the original resource from Scene A. Very weird...

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

5 participants