Menu
CoddyTech

The Scene Tree

Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 4 of 28.

Nodes are arranged in a tree. A node can have children, and each child can have children of its own. Open the Scene tab under the game to see the tree. Main holds the background, the floor and the Robot. The robot holds its antenna, bulb, body, face, eyes and mouth.

Children move with their parent. When the robot moves, its eyes move too.

name is a node's name, and get_child_count() counts its children. print() takes several values with a comma between each, and prints them on one line:

print(name, " has ", get_child_count(), " parts")
challenge icon

Challenge

Easy

Make the robot say how many parts it has.

  1. In _ready(), change print(name) so it prints four values: name, " has ", get_child_count() and " parts".
  2. Put a comma between each value, as in the example above.

Press Play: the Console shows Robot has 7 parts. Then Check.

Try it yourself

extends Node2D

func _ready():
	print(name)

All lessons in Nodes and Scenes

Practice on your own: Godot playground