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
EasyMake the robot say how many parts it has.
- In
_ready(), changeprint(name)so it prints four values:name," has ",get_child_count()and" parts". - 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
1Your First Godot Game
What Is Godot?Ready Runs OncePrint in GodotThe Scene TreeSet a PositionMove a Node OncePractice on your own: Godot playground