Killzone does not restart game

Godot Version 4.3

Question

This is my second attempt at making a 2d platformer. I was following Brackey’s tutorial the first time, which went relatively smoothly. I tried to recreate it on my own with only the code, but now there’s something wrong. Whenever the character falls off a platform and into the void, instead of dying and restarting at the beginning of the level, you can still control the character from below the camera.

Here is the code I used:

Is there anything wrong with it?

When/where do you actually call _on_timer_timeout()?

I’m not sure what you mean. I have it written down exactly as it’s written in my question, below the _on_body_entered() function

That’s the definition of the function, but there’s no call to it. I guess you connected the signal, but are you sure it gets called? You could set a breakpoint or just use a print message inside _on_timer_timeout().

You’re using an Area2D for death detection, which is fine, but you’re freeing the player’s CollisionShape2D before the scene reload. This could be causing the issue where the player remains controllable. The approach of freeing the collision shape might be interrupting the proper death sequence.

extends Area2D

@onready var timer = $Timer

func _on_body_entered(body) -> void:
    if body.is_in_group("player"):  # Make sure we're only affecting the player
        print("You died!")
        # Disable player input instead of removing collision
        body.set_process_input(false)
        body.set_physics_process(false)
        Engine.time_scale = 5
        timer.start()

func _on_timer_timeout() -> void:
    Engine.time_scale = 1
    get_tree().reload_current_scene()

I tried using your code you showed below, but the issue still persists. How do I make the collision shape still register before the scene reload?

Make sure your Area2D is wide enough to catch the player no matter where they fall and Instead of removing the collision shape you might want to disable player input

It may be that you copied the code but did not actually connect the signal. Make sure by checking if there is any signal connected symbol visible