Get node path returned by Ctrl+Shift+C

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

Hey there, so a bit of a weird question.

If you select a node and press Ctrl+Shift+C (or right click-> Copy Node Path), it will return the path of that node, but minus the root of the scene. E.g if you were to press the key combo on AnimationPlayer on the scene structure: Level1->Player->Animation-Player, it will return “Player/AnimationPlayer.”

How do I get that kind of node path in code?

:bust_in_silhouette: Reply From: DDoop

From the Node docs:
NodePath get_path_to ( Node node )

“Returns the absolute path of the current node. This only works if the current node is inside the scene tree”


var node_path = get_path_to($ChildNode/SubChild)
# should eval roughly to '/root/Self/ChildNode/SubChild' but I didn't actually run this in a scene to test it :)

Yeah, i’m not looking to get the absolute path to the current node. I just want to know if there’s something that returns the same path as when you press Ctrl-Shift-C (or right click-> Copy Node Path) on a current node. So in your example, if i was on the SubChild node and Self is the 2D is the starting node in the editor, is there a function that returns “ChildNode/Subchild”?

anark10n | 2022-11-15 05:16