Menu
CoddyTech

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, shorter

get_node() takes the path as text. $ is a shorter way to write it. A wrong path stops the game with Node not found.

challenge icon

Challenge

Easy

Make the robot look up and to the left.

  1. In _ready(), reach the eyes with get_node("Face/Eyes").
  2. Set their position to Vector2(-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