Same Node second times

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Star Frog

I have the same node that I actually need in two places on the tree. Is there a way to do this directly, or is there a way to solve this with code?

Looking forward to answers! A nice week!

:bust_in_silhouette: Reply From: njamster

The same node cannot be in two different places simultaneously. However, you can add two instances of a scene to the tree. I’m not sure what you mean by “directly” though. More direct than adding it to place A first and place B after that? No.

:bust_in_silhouette: Reply From: Sween123

If you mean the exact node instance you create, then no, the node is what it is, one can only exists in one place, because itself is an individual.
If you mean the node instances with the same type, for example, monster slime, and you want have this kind of monsters in different scenes, then yes. Save the scene and you simple do instancing through either the editor (The link like icon) directly or using add_child() in code.
Usually, when we want the same instance to be in different place (Exactly the same), that’s what’s called referencing, this may be done in code. You reference the node using variable like var NODE = get_node("/root/..../My_Node"). It can exists in different scripts, but not in different scenes. (Like a person can’t exists at two different places at the same time, but the person’s properties and infos can exist on different devices. When you send him 1$, you can send to his ACCOUNT1, ACCOUNT2…)

Thank you so much! Just what I was looking for.

Star Frog | 2020-04-08 14:46