Reach to node from another scene

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

Hi, i normaly reach any node like

onready var node = get_node("node_name") or if outside of the scoop

onready var node = get_node("../node_name")

but i need to get position of a node belong the diffrent scene,

the thing is:

----player | kinematic body

enemy scene

–enemy | kinematic body

i have script in my enemy node, and i m try to get player position, so that i can use look_at and also follow the player.
i did try some thing like

get_tree().get_root().get_node("node_name") etc...

didn’t work.

ps: Player is placed in the main scene as a node.
But my enemy scene get instanced more then once at the main scene as enemy1. and get instanced randomly.

:bust_in_silhouette: Reply From: Firty

Use get_parent ().
If the player is the enemy’s brother (both are within the same node) get_parent().get_node("Player").position
Will resolve

Example of tree:


If you use get_parent() in enemy script, will return his father who is Node.

This way will also solve. no need to get_tree().get_root()


Firty | 2020-10-30 17:57

well thank you for anwser but i think i didnt expres the problem correcly,

this is my enemy scene :

and this is my main scene :

im trying the get player position from the script attact to enemy1.

so that i can made enemys to look at the player, and follow them. whlie im not sure if it will be work or not, cause there are more then 1 instanced enemy1 at the scene.

morningkingdom | 2020-10-30 18:35

It will work even with 1000 instanced enemies.
You have to obviously change from player to karakter.


If still not work maybe need go to grandfather


If still not work maybe need use transform


When you run game change from local to Remote and you can see exactly where your nodes are in the tree.

larrxi | 2020-11-01 02:43