Clear the Path
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 18 of 27.
To remove every node of a kind, loop over the group and free each node:
for crate in get_tree().get_nodes_in_group("crates"):
crate.queue_free()You cannot free the list itself. get_nodes_in_group("crates").queue_free() stops the game with an error, because a list is not a node.
Three crates block the way to the right. They are all in the group crates.
Challenge
MediumThe switch removes only Crate1. Make it remove every crate in the group crates. Then walk through.
Try it yourself
extends Node2D
func _ready():
$Switch.body_entered.connect(_on_switch_body_entered)
func _on_switch_body_entered(body):
$Crate1.queue_free()
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