Menu
CoddyTech

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 icon

Challenge

Easy

Make the coin disappear when you walk into it.

  1. In _on_body_entered, replace pass.
  2. Free the coin with queue_free().

Press Play and walk into the coin: it is gone. Then Check.

Try it yourself

extends Area2D

func _ready():
	body_entered.connect(_on_body_entered)

func _on_body_entered(body):
	pass

All lessons in Signals and Collisions

Practice on your own: Godot playground