0 votes

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

enter image description here

in Engine by (15 points)

1 Answer

+1 vote
Best answer

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")
by (21,539 points)
selected by

This worked, thank you.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.