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
MediumMake the switch remove every crate.
- In
_on_switch_body_entered, replace theCrate1line with aforloop over the groupcrates. - Free each crate inside the loop.
Press Play and step on the switch: every crate is gone and you walk through. Then Check.
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