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

Merging instanced node from another scene bug #31744

Closed
SoulForMachine opened this issue Aug 28, 2019 · 3 comments
Closed

Merging instanced node from another scene bug #31744

SoulForMachine opened this issue Aug 28, 2019 · 3 comments

Comments

@SoulForMachine
Copy link
Contributor

Godot version:
v3.1.1.stable.official
v3.2.dev.custom_build.e71cf83f

OS/device including version:
All

Issue description:
When using Merge From Scene, and then selecting a node in another scene that is an instantiation of a third scene, and then checking Editable Children on the merged node, all children of that node will be duplicated.

Steps to reproduce:

  • Create a scene, add root Node2D, name it Scene1, add a Sprite node as child. Save as Scene1.tscn.
  • Create a scene, add root Node2D, name it Scene2, instantiate Scene1.tscn as child. Save as Scene2.tscn.
  • Create a scene, add root Node2D, name it Scene3.
  • On root node Scene3, right-click and use Merge From Scene, select Scene2.tscn, select Scene1 node.
  • On newly merged node, right-click and check Editable Children.
  • Select the grayed Sprite node move it a little bit.
  • Save the scene as Scene3.tscn and run it.
  • The scene in game has 2 sprites displayed.
  • Close the game and close the Scene3.tscn tab in editor.
  • Reopen Scene3.tscn again. Now 2 Sprite nodes are visible in editor too, one is grayed and one isn't. When one is selected the other is automatically selected too.

Minimal reproduction project:
MergeInstanceTest.zip

@SoulForMachine
Copy link
Contributor Author

I think I found out what the problem is. EditorSubScene, from which a sub-tree is selected to merge, did not instance the source scene with PackedScene::GEN_EDIT_STATE_INSTANCE, so if the node we are merging is in fact an instanced scene in the source scene, it won't have its data.instance_state set. Later, when Editable Children is checked for the merged node and the scene is saved, SceneState::_parse_node will treat child Sprite of the merged node as not being part of the instanced scene and will write it into the tscn.

[gd_scene load_steps=3 format=2]

[ext_resource path="res://Scene1.tscn" type="PackedScene" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]

[node name="Scene3" type="Node2D"]

[node name="Scene1" parent="." instance=ExtResource( 1 )]

[node name="Sprite" type="Sprite" parent="Scene1"]
position = Vector2( 160, 31 )
texture = ExtResource( 2 )

[editable path="Scene1"] 

So the sprite is duplicated. I changed the scene instantiation call in EditorSubScene::_path_changed to:
scene = ps->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);

This fixes the problem, but some more feedback would be helpful since I'm new to Godot. I see that @reduz and @akien-mga touched most of this function, so please advise if this is correct solution.

@KoBeWi
Copy link
Member

KoBeWi commented Sep 14, 2020

Still valid in ee36e08

@akien-mga akien-mga added this to the 4.0 milestone Feb 25, 2021
@akien-mga
Copy link
Member

Fixed by #34892 and #45943.

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

3 participants