How to store another node in a script as a variable?

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

So i have a script where i want to store another object in a variable, a kinematicbody2d.

i cant use $… or get_node(…), because the object is not a child of the camera2d (which has this script), or maybe there is a way for $… or get_node(…) to get nodes outside of camera2d?

like unity where we make a variable that stores another gameobject in it, in godot i want a variable that stores another node.

:bust_in_silhouette: Reply From: exuin

In node paths, “…” means the parent of the current node. If the body is a sibling of the camera, the node path is “…/KinematicBody2d”.

thanks, it worked for me with get_node()

rz | 2021-04-26 09:25

:bust_in_silhouette: Reply From: blohod

Variables can reference nodes, just make sure that you are using the correct nodepath, see NodePath — Godot Engine (stable) documentation in English