You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Godot v4.2.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1050 Ti with Max-Q Design (NVIDIA; 31.0.15.4617) - Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 Threads)
Issue description
If I create a custom resource that has some runtime-mutable state (that is, the game modifies the resource during gameplay), and then store that resource in an Array used by multiple subscenes in my main scene, the mutable state ends up shared, even if Local to Scene is checked. If the resource is top-level instead of inside an Array, it works as expected (unshared).
If it's not a bug and it's definitely by design, can we document this behavior somewhere? Local to Scene isn't even mentioned in the Resources tutorial, but some kind of best practice callout should probably be added here. Either "be careful when using Resources in Arrays" or "avoid mutable state inside Resources"?
Steps to reproduce
Create a custom resource. It should have at least one field modified by the game at runtime, e.g. a checkbox to indicate whether the animation it represents has completed.
Store this resource in an Array on a scene.
Write a script and attach to the scene that uses the resource.
Instantiate this scene multiple times and add it to the main scene.
Observe that the mutated state is shared across all instances.
For the attached project, just run the main scene, then click on the first image, then the second image.
I've attached a simple project where there's a stateful animation resource that's in an array shared by two instances. Because I've chosen Resource > Local to Scene for the AnimNames resource (and tried Make Unique on that resource for good measure), I expect the AnimNames resource to be fully independent between the two images. But it's actually shared.
What I expect the behavior to be when clicking on the images:
20231201071248.mp4
What actually happens when clicking on different instances. The jerking behavior is because it's unexpectedly playing the wrong animation.
20231201071318.mp4
The text was updated successfully, but these errors were encountered:
Godot version
v4.2.stable.official [46dc277]
System information
Godot v4.2.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1050 Ti with Max-Q Design (NVIDIA; 31.0.15.4617) - Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 Threads)
Issue description
If I create a custom resource that has some runtime-mutable state (that is, the game modifies the resource during gameplay), and then store that resource in an Array used by multiple subscenes in my main scene, the mutable state ends up shared, even if Local to Scene is checked. If the resource is top-level instead of inside an Array, it works as expected (unshared).
Unexpected sharing of state between instances:
20231201071318.mp4
What I'm looking for:
Steps to reproduce
For the attached project, just run the main scene, then click on the first image, then the second image.
Minimal reproduction project
LocalToScene_GD.zip
I've attached a simple project where there's a stateful animation resource that's in an array shared by two instances. Because I've chosen
Resource > Local to Scene
for the AnimNames resource (and triedMake Unique
on that resource for good measure), I expect the AnimNames resource to be fully independent between the two images. But it's actually shared.What I expect the behavior to be when clicking on the images:
20231201071248.mp4
What actually happens when clicking on different instances. The jerking behavior is because it's unexpectedly playing the wrong animation.
20231201071318.mp4
The text was updated successfully, but these errors were encountered: