Game freezes after adding function ' _on_Area2D_body_entered(body): '

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By josephbradley

So when my player falls off the map, I want the level to reload. I have used an area2d with a collisionshape2d to create an area that will call a function when the player collides with this area. However, when the game is run with this code included, the player will animate through a few frames then the game completely freezes before I can even move the player.

func _on_Area2D_body_entered(body):
get_tree().change_scene('res://level1.tscn')

If I delete this code, or set monitoring to off, and re-run the game it will not freeze.

Below is a screenshot of my level design.

Level design

Any help would be greatly appreciated :slight_smile: - Is this a bug or am I doing something stupid?

I am sorry this is my mistake.

look
https://forum.godotengine.org/24773/how-to-load-and-change-scenes

ramazan | 2022-07-12 08:07