Skip to content

Godot:NodePath

Pre-parsed scene tree path.

Examples

C#

선행 슬래시(/)가 없다면 현재 노드의 상대적 위치 (Relative) 를 나타낸다.

  • @"A": Immediate child A
  • @"A/B": A's child B
  • @".": The current node.
  • @"..": The parent node.
  • @"../C": A sibling node C.

선행 슬래시(/)는 SceneTree 에서 절대 위치 (Absolute) 이다.

  • @"/root": Equivalent to get_tree().get_root().
  • @"/root/Main": If your main scene's root node were named "Main".
  • @"/root/MyAutoload": If you have an autoloaded node or scene.

gdscript

# No leading slash means it is relative to the current node.
^"A" # Immediate child A
^"A/B" # A's child B
^"." # The current node.
^".." # The parent node.
^"../C" # A sibling node C.

# A leading slash means it is absolute from the SceneTree.
^"/root" # Equivalent to get_tree().get_root().
^"/root/Main" # If your main scene's root node were named "Main".
^"/root/MyAutoload" # If you have an autoloaded node or scene.

Examples of valid NodePaths (assuming that those nodes exist and have the referenced resources or properties):

# Points to the Sprite2D node.
"Path2D/PathFollow2D/Sprite2D"

# Points to the Sprite2D node and its "texture" resource.
# get_node() would retrieve "Sprite2D", while get_node_and_resource()
# would retrieve both the Sprite2D node and the "texture" resource.
"Path2D/PathFollow2D/Sprite2D:texture"

# Points to the Sprite2D node and its "position" property.
"Path2D/PathFollow2D/Sprite2D:position"

# Points to the Sprite2D node and the "x" component of its "position" property.
"Path2D/PathFollow2D/Sprite2D:position:x"

# Absolute path (from "root")
"/root/Level/Path2D"

Returns a node path with a colon character (:) prepended, transforming it to a pure property path with no node name (defaults to resolving from the current node).

# This will be parsed as a node path to the "x" property in the "position" node.
var node_path = NodePath("position:x")
# This will be parsed as a node path to the "x" component of the "position" property in the current node.
var property_path = node_path.get_as_property_path()
print(property_path) # :position:x

See also

Favorite site