Instantiating scene containing nodepaths multiple times gives strange results

Godot Version

4.2

Question

I have a scene which looks like this:

  • MyObject (Node3D)
    • MySubObject (Node3D)

In MyObject, I have a Script like this:

@export var target: Node3D

… and in the editor, I assign MySubObject as target. All fine.

Now, if I instantiate this scene multiple times at different positions, then all of the target references will point to the same node.

Why is that? I would have expected that every instance of MyObject would point to its own MySubObject. How can I fix the situation such that every instance points to its own target?

Nevermind, I was copying the MyObject nodes around instead of re-instantiating them. Apparently the godot editor then explicitly adds the nodepath to the original MySubObject in the TSCN file. I don’t fully understand why this is the case, but I can work with it.