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 is ignored for arrays and dictionaries (including surface materials) #71243

Closed
RedMser opened this issue Jan 11, 2023 · 1 comment · Fixed by #87268
Closed

Comments

@RedMser
Copy link
Contributor

RedMser commented Jan 11, 2023

Godot version

Tested again on 4.2 beta 2

System information

Windows 10

Issue description

Exporting a resource that is marked as local to scene works as expected, both when exposed on a node and on a sub-resource.

But when the resource is a part of an array or dictionary, local to scene no longer works. The resource instances are shared.

Steps to reproduce

  • Create a node or resource which exports an array or dictionary which contains local-to-scene resources.
  • Instantiate the scene multiple times.
  • On the resource instances, observe get_local_scene() == null and modifications are shared between instances, despite resource_local_to_scene == true.

Minimal reproduction project

CustomLocalToScene.zip

Two instances of a scene are included in the root. On the second instance, all field values are *= 2. All resources that are in arrays and dictionaries are modified on both instances, while the modifications should all only affect one of the two instances.

Following is the current output log showing resource_local_to_scene, the field's integer value and get_local_scene():

Output Log
pre-modified first ---------
simple:
true	1	LocalToSceneTests1:<Node#26491224610>
array:
true	2	<Object#null>
true	3	<Object#null>
dict:
true	4	<Object#null>
sub:
true	5	LocalToSceneTests1:<Node#26491224610>
sub array:
true	6	<Object#null>
sub dict:
true	20	<Object#null>
check first --------- (should be same as above)
simple:
true	1	LocalToSceneTests1:<Node#26491224610>
array:
true	4	<Object#null>
true	6	<Object#null>
dict:
true	8	<Object#null>
sub:
true	5	LocalToSceneTests1:<Node#26491224610>
sub array:
true	12	<Object#null>
sub dict:
true	40	<Object#null>
check second --------- (should be *= 2 on each field)
simple:
true	2	LocalToSceneTests2:<Node#26575111315>
array:
true	4	<Object#null>
true	6	<Object#null>
dict:
true	8	<Object#null>
sub:
true	10	LocalToSceneTests2:<Node#26575111315>
sub array:
true	12	<Object#null>
sub dict:
true	40	<Object#null>
@RedMser
Copy link
Contributor Author

RedMser commented Jan 11, 2023

I believe these checks need to be expanded to also traverse arrays and dictionaries:

if (value.get_type() == Variant::OBJECT) {
//handle resources that are local to scene by duplicating them if needed

if (p.get_type() == Variant::OBJECT) {

if (p.get_type() == Variant::OBJECT) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants