Node.Duplicate() Should Duplicate Data, Not just Node Branch #6512
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
Your reply seems to imply some things about intended behavior: that Duplicate is intended to duplicate the entire branch and not just the parent node. Obviously then it must duplicate child nodes, because child nodes aren't references (although I suppose it could use instances for children). If this is the case, though, perhaps "Duplicate Branch()" would be more clear? My recommendation would still be parents-only by default, and children according to flags, as that was also what others seemed to expect on Discord when I described my problem. Only copying @export variables is a pain, because you can't export a variable of type "Variant". I really think it should just copy all the node's data. I really think it would be silly to have to write my own recursive Node-duplicating function to get around this. And now that I think about it, doesn't the current implementation even duplicate child nodes the parent node may not be the owner of? PackedScene.pack() doesn't let you group nodes in violation of ownership, so why does this function? |
Beta Was this translation helpful? Give feedback.
-
Node.duplicate() is a strange function. I was expecting it to work like a class's copy constructor in most languages. To my surprise, I discovered it actually made a deep copy of a node, and it's children, but with its data set to null. Only, not actually. A function that would act like a runtime equivalent of what instantiate() does for PackedScene() on a branch in the scene tree at runtime would be useful. Node.duplicate() seem to make such a copy, but with the internal data in the branches variables lost, and set to null. That's not very useful.
I post here first, because with 4.0, I don't know that there's something I'm missing that I ought to know about before making a formal proposal. Maybe there is some other intended method of duplication, and the function is actually meant for something else, and the issue is more one of naming.
Beta Was this translation helpful? Give feedback.
All reactions