0 votes

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

Godot version latest
in Engine by (12 points)

1 Answer

0 votes

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.

by (7,190 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.
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 webmaster@godotengine.org with your username.