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

Instanced scenes share their metadata if the saved PackedScene contains saved metadata #29189

Closed
mrcdk opened this issue May 26, 2019 · 5 comments · Fixed by #32416
Closed

Instanced scenes share their metadata if the saved PackedScene contains saved metadata #29189

mrcdk opened this issue May 26, 2019 · 5 comments · Fixed by #32416
Assignees
Milestone

Comments

@mrcdk
Copy link
Contributor

mrcdk commented May 26, 2019

Godot version:

Godot 3.0.6, Godot 3.1.1 and latest Godot master 0d8f1ba

OS/device including version:

Windows 10

Issue description:

If the Control's children are instances of the same scene the children of the same scene will share the same metadata.

Instanced scenes share their metadata if the saved PackedScene contains saved metadata in the scene's root node.

This is problematic because master now saves metadata for each control and some controls like the TabContainer and its TabContainer.set_tab_*() methods use the child's metadata to change some internal values.

As far as I can tell this doesn't happen with Node, Node2D or Spatial instances.

Steps to reproduce:
Open the attached MRP and run the Main* scenes. Only MainControl will show:

True
False
False
True

The expected result (and the result you will get with all others) is:

False
False
False
False

Notice that InstancedControl.tscn and AnotherControlInstanced.tscn contains saved metadata while the other *.tscn don't. If you add metadata manually the problem will appear in those instances.

Minimal reproduction project:

test_meta_instances.zip

@mrcdk
Copy link
Contributor Author

mrcdk commented May 26, 2019

Tested on Godot 2.1.5 and it doesn't happen there so it's probably a 3.0+ issue.

Nevermind, read the following post.

@mrcdk
Copy link
Contributor Author

mrcdk commented May 26, 2019

Okay, my bad, I've found the issue. It doesn't happen in 3.0.x or 3.1.x It only happens on master.

Master now saves the following metadata automatically in each PackedScene.:

__meta__ = {
"_edit_use_anchors_": true
}

And that's what's causing the problem in the first place. I manually added metadata to one of the instanced *.tscn files and I could replicate the issue in 3.0+ but not in 2.1.5

I made a quick fix here

godot/core/object.cpp

Lines 437 to 443 in 0d8f1ba

} else if (p_name == CoreStringNames::get_singleton()->_meta) {
//set_meta(p_name,p_value);
metadata = p_value;
if (r_valid)
*r_valid = true;
return;
}
and modified metadata = p_value; to metadata = p_value.duplicate(true); (deep duplicate) which fixed the issue in master but because it doesn't happen in 2.1.5 I think that's not the correct fix.

@mrcdk mrcdk changed the title Control's children share the same metadata if they are instances of the same scene Instanced scenes share their metadata if the saved PackedScene contains saved metadata May 26, 2019
@akien-mga akien-mga added this to the 3.2 milestone May 26, 2019
@Calinou
Copy link
Member

Calinou commented Aug 15, 2019

I noticed an issue tangential to this on commit b030834, not sure if it's related. Metadata such as edit locking or Position2D gizmo extents doesn't get saved when you change it on an instanced scene in the scene tree dock. It will be lost when you reload the scene.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 16, 2019

Might be related/duplicate of #20648

@akien-mga
Copy link
Member

Fixed by #32416.

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