godot icon indicating copy to clipboard operation
godot copied to clipboard

Duplicating a Node in Editor references original Node

Open hislittlecuzingames opened this issue 1 year ago • 3 comments

Tested versions

4.2.1 Mono "Godot Engine v4.2.1.stable.mono.official [b09f793f5]"

System information

Windows 10 64 bit. Forward +. Godot 4.2.1 Mono from godot website

Issue description

When I duplicate a node that is a "prefab" node with functionality referenced in itself, the duplicate references the original node.

I didn't test GD Script.

Steps to reproduce

  1. Create a node scene.
  2. Add a script and export reference a node in the scene.
  3. create a new scene to put the first node in.
  4. duplicate the node
  5. notice the duplicate references the original.

Example of how to reproduce: Create a new UI scene. Add a label to the scene and give it the text "foobar" Add a button to the scene. Add a script to the root node. Give the root node the following C# code: [Export] Label myLabel; public void ChangeLabelText(){ myLabel.text = "Changed this node." } Connect the Button to the function "ChangeLabelText"

Create a new scene. Drag the "prefab" into this scene. Click this instance, and press "Control + D" to duplicate. Duplicate as many times as you want.

Run current scene. (F6 hotkey on windows)

Click the button on a duplicate, and it changes the text of the "original" and not the duplicate as expected.

If you click the original, it still changes the text of the original as expected.

Minimal reproduction project (MRP)

Just basic Godot nodes. See "Steps to reproduce" for information.

hislittlecuzingames avatar Mar 07 '24 00:03 hislittlecuzingames

Seems missing "set My Label to reference the prefab node itself" in the steps?

~~If that's the case, the duplicated node is expected to still referencing the original node. The value of myLabel is a certain node. Setting it to self is not different from others.~~ Update: No, the issue is about instantiated scene setting a property's default value to a node that it owns.

timothyqiu avatar Mar 08 '24 09:03 timothyqiu

Regardless of whether this is a bug or intended behavior, I find this very unintuitive. If I duplicate a node that holds references to its own children nodes, I would not expect those references to still be of the original node's children.

slippery39 avatar Mar 14 '24 23:03 slippery39

Can confirm and reproduce with your steps. Additionally, in my tests, I found the following: In Step 3, after instancing the scene once, the exported field is already marked as "changed" and displays the revert-button next to it: image

Then, when duplicating that node, a relative path pointing to the first node is used in the field: image

There is a workaround to this problem, which makes me firm in my suspicion that this is indeed a bug:

  • Before duplicating the node, click the "Revert"-Button next to the exported field on the first instance.
  • Duplicate the node. You will observe that both the original and the duplicate do not show the "revert" button, and both fields will reference to their own child node

This workaround, however, is extreme error prone. It's easy to forget to revert all fields when instancing a scene. For this reason, I currently avoid exposing node fields on scene roots.

Faradax avatar Mar 24 '24 11:03 Faradax

Oh, I see what you mean now. I thought setting the property happens from outside the scene.

This is indeed a bug of node exports. Exporting a NodePath works fine in this case.

timothyqiu avatar Mar 25 '24 03:03 timothyqiu

I think it's fixed in 4.3.

KoBeWi avatar Mar 27 '24 16:03 KoBeWi