Remove a Node
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 15 of 27.
A coin you picked up should be gone, not hidden, so nothing can touch it again. queue_free() removes a node and all its children from the game:
func _on_body_entered(body):
queue_free()Called on its own, queue_free() removes the node the script is on, here the coin.
The name says "queue" because Godot frees the node at the end of the current frame, not at once. Other code may still use the node until then. You will see why this matters in a few lessons.
Challenge
EasyMake the coin disappear when you walk into it. Free it in _on_body_entered.
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
pass
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