-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Duplicating a scene also duplicates child nodes' UIDs. #83575
Comments
When copying a node, the exported variable GD.Print($"_mesh UID: {_mesh.GetInstanceId()} ", $"child UID: {GetNode("MeshInstance3D").GetInstanceId()}"); Although the [node name="Node3" parent="." instance=ExtResource("1_vwf8e")]
[node name="Node4" parent="." instance=ExtResource("1_vwf8e")]
[node name="Node5" parent="." node_paths=PackedStringArray("_mesh") instance=ExtResource("1_vwf8e")]
_mesh = NodePath("../Node4/MeshInstance3D") |
If you instantiate this scene through code, everything works fine, the MeshInstance3D UID is unique. |
The problem is that you use If you specify @export_node_path("MeshInstance3D") var _mesh |
When I duplicate a PackedScene, its child nodes are also duplicated. I expect all the links to the original children to be replaced with links to the new children. |
There are two ways to think about it:
Consider a case that what the exported variable cache is a node in the main scene. If you copy the node, and then paste it in a different node tree depth, keep the same instance may be better. In my opinion: Node instance is suitable for the above case; and |
Are you saying that I am using ExportAttribute for a wrong use case? |
Please see C# exports Nodes and Node.GetNode*. Use |
"Since Godot 4.0, nodes can be directly exported without having to use NodePaths. This reads like exporting Nodes is supposed to replace NodePaths and should work the same way. Duplicating scenes is the most basic feature of any engine. ExportAttribute with nodes works fine if you instantiate the scene through code, or if you drag the node from the file system window to the or if you use Instantiate Child Scene (Ctrl+Shift+A). |
Overwriting the property
If you are just using it in a simple scene (no sub-scene, or passing node references from the main scene into the sub-scenes), yes, they work the same. Because they reference the same node instance and have the same relative node path, Ctrl + D creates sibling nodes.
This is exactly the case where |
Why would you ever want the copied scene to reference child nodes from the main scene? There is no use case for that. Imagine having a character scene with a script that references a hand node. This makes using ExportAttribute with nodes completely unpredictable, therefor useless. Why even have it at all? |
I also encountered this bug. When duplicating, scenes, all duplicated scenes reference the internals of the source scene. Which is incorrect. They should retain their internal structure. The same issue occurs if the node is copy/pasted.
It is unexpected, because it doesn't make any sense from a usability perspective and there is no use case for which this would be useful. Furthermore for the most default use case this behaviour is simply incorrect. |
It would seem the workaround for this is to make sure the exported properties are not in the top level node, but in a node further down the hierarchy. Then everything works as expected. But again, this is a serious usability issue, making duplicating nodes very error prone. |
Can't reproduce on master, I think #83343 fixed it. |
Godot version
4.1.2.stable.mono
System information
Windows 11
Issue description
Duplicating a scene duplicates UIDs of all sub-nodes, such as MeshInstance3D.
Steps to reproduce
There is a single script, PrintChildUID, that exposes a MeshInstance3D node and prints its UID in the _Ready method.
The scene print_node.tscn is a simple node3D scene with the PrintChildUID script and a single MeshInstance3D child
Repro steps:
Open main_scene.tscn
Duplicate any node in the scene
Launch the game
Observe that UIDs of duplicated nodes are all the same in the output, while they should be different.
Minimal reproduction project
uid-bug-repro.zip
The text was updated successfully, but these errors were encountered: