Menu
CoddyTech

Every Node in a Group

Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 13 of 27.

get_tree().get_nodes_in_group("lamps") gives you every node in the group as a list. Go through the list with for:

for lamp in get_tree().get_nodes_in_group("lamps"):
	lamp.visible = true

The lines under for run once for each node. Each time, lamp is the next node. Five lamps means five turns.

get_tree() is the whole game's tree, so this finds the lamps anywhere in the scene. Add a sixth lamp to the group and this code lights it too.

challenge icon

Challenge

Medium

Pressing E turns on only Lamp1. Make it turn on every lamp in the group lamps with a for loop. The lamps stay off until you press E.

Try it yourself

extends Node2D

func _process(delta):
	if Input.is_action_just_pressed("action"):
		$Lamp1.visible = true
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Signals and Collisions

Practice on your own: Godot playground