Get a node in another scene

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

I’m having troubles getting a node in a different scene. If you can see in the picture, I’m trying to run a function in the root node of the Player scene from the Enemy scene. I tried to use

onready var player = get_node("../Player/Player/Player")

:bust_in_silhouette: Reply From: kidscancode

Node paths refer to where the nodes are in the Scene Tree, not where you’ve saved the scene files. When the game is running, there is only one scene. The PackedScenes you have instanced are all located in that scene tree. So what you need is the path from the enemy node to the player node when the game is running. You haven’t shared that information, but if, for example, the Player and Enemy are siblings, then the path from Enemy to Player would be:

var player = get_node("../Player")

This worked, thank you.

Luke Strong | 2019-03-17 16:09