How can i get_node from another scene?

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

Hi, i’m french, so sorry if my english isn’t very good.

-I made my KinematicBody2D (player) in a scene and after I instantiated it in my main scene.
-I made an Area2d (object) in an other scene that I also instantiated in my main scene.
I added a signal that detect if a KinematicBody enter in:

func _on_object_body_entered(body: KinematicBody2D): if not body == null: pass
I want to get_node() of the player to add_child() the object, but i don’t know how to get_node() from another scene. I know that i can use get_tree().get_root().get_node("scene_main_node/node_wanted"), but its not working

:bust_in_silhouette: Reply From: exuin

In this case, you don’t need to get a reference to the player since you already have it. The body variable should refer to the player when the player enters the Area2D.

However, if you want to get a node from another scene, you can use an absolute path from the root like you said. I’m not sure exactly why your path isn’t working, but it’s probably wrong. You can check the node tree during runtime with the “Remote” tab to get the path of the player.