Node Paths
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 20 of 28.
In this scene the eyes sit deeper in the tree. Face is a child of Robot, Eyes is a child of Face, and the two eyes are children of Eyes.
$Eyes finds nothing now, because Eyes is a grandchild of the robot. To reach it, write a path: the names on the way down, with a / between them.
get_node("Face/Mouth").position.y += 2
$Face/Mouth.position.y += 2 # the same, shorterget_node() takes the path as text. $ is a shorter way to write it. A wrong path stops the game with Node not found.
Challenge
EasyMake the robot look up and to the left.
- In
_ready(), reach the eyes withget_node("Face/Eyes"). - Set their
positiontoVector2(-4, -3).
Press Play: both eyes move up and left, and the face and mouth stay put. Then Check.
Try it yourself
extends Node2D
func _ready():
pass
All lessons in Nodes and Scenes
Practice on your own: Godot playground