0 votes

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!

asked Apr 7 in Engine by Star Frog (43 points)

2 Answers

+1 vote
Best answer

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....)

answered Apr 8 by Sween123 (726 points)
selected May 5 by avencherus

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

+1 vote

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.

answered Apr 8 by njamster (8,904 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.