CHALLENGE 1: A Coin That Waits for Its Sound to Finish ==================================================================== TASK ---- Rebuild the Coin scene from Chapter 6 with an added AudioStreamPlayer2D. On collection, hide the sprite and disable the collision shape immediately, play the sound, await its finished signal, and only then call queue_free(). SCENE STRUCTURE ---------------- Coin (Area2D) |-- Sprite2D |-- CollisionShape2D |-- AudioStreamPlayer2D <- Stream: any short pickup sound effect SOLUTION CODE (attached to Coin) -------------------------------------- extends Area2D func _ready() -> void: body_entered.connect(_on_body_entered) func _on_body_entered(body: Node2D) -> void: if body.is_in_group("player"): $CollisionShape2D.set_deferred("disabled", true) $Sprite2D.hide() $AudioStreamPlayer2D.play() await $AudioStreamPlayer2D.finished queue_free() WHY THIS WORKS AS AN ANSWER ---------------------------- The moment the player overlaps the coin, three things happen immediately, in this order: the CollisionShape2D is disabled (using set_deferred, since physics shapes can't safely be changed mid- collision-callback - Godot defers the actual change to the next safe point), the Sprite2D is hidden, and the sound starts playing. From the player's perspective, the coin has already visually and functionally disappeared at this point - it can no longer be collected again, and it's no longer visible. The node itself, however, is deliberately kept alive a little longer: await $AudioStreamPlayer2D.finished pauses this specific function (not the whole game - Chapter 7's own distinction) until the AudioStreamPlayer2D's own finished signal fires, which happens exactly when the sound clip naturally ends. Only then does queue_free() actually remove the Coin node. If queue_free() were called immediately instead (as in Chapter 6's simpler version), the AudioStreamPlayer2D child would be destroyed along with its parent before the sound had a chance to finish, cutting it off abruptly - exactly the problem this chapter's own warning describes.