Area2d crashing game/level

Question

Idk what is making it crash. I originally had it when I imported the pipe scene sending a signal to the area2d and when the player enters to close the window. When I added a second area2d everything broke. I tried adding a second signal to the first area2d script, moving it to the world scene, but that didn’t work either.

pipe scene
area2d

| sprite

| collision

| area 2d

| | sprite

| | collision

extends Node2D
@onready var player: CharacterBody2D = $CharacterBody2D

func _on_area_2d_area_entered(area: Area2D) -> void:
	if player.is_in_group("player"):
		get_tree().quit()


func _on_top_area_shape_entered(area_rid: RID, area: Area2D, area_shape_index: int, local_shape_index: int) -> void:
	if player.is_in_group("player"):
		get_tree().quit() 


func _on_area_2d_area_shape_entered(area_rid: RID, area: Area2D, area_shape_index: int, local_shape_index: int) -> void:
	if player.is_in_group("player"):
		get_tree().quit() 

What do you mean by crash?

When I mean crash I mean when I run the game to debug. It opens for split second, and then immediately closes.

It’s going to be difficult to diagnose the problem without the full project or more info. (note that .zip uploads seem to be blocked here)

Screen shots might help (It’s probably because I’m new to the phone and that’s why no zip can be uploaded). So there are two scenes the first one is the main scene the second one is the tree of the scene that is causing problems. There isn’t code for the second one because it’s linking into the main one when it gets imported in.

Do your areas overlap? have your tried printing before quitting the game, to see if there is an overlap?

It looks like the player enters the area and it instantly quits. You probably call get_tree().quit() on the first frame.

Is it attached to the player character and meant to detect other players? Then just add if player != references to overlapping areas to filter away the player it is attached to

The area2ds aren’t overlapping and I don’t think it can physically happened first frame. Also just to double check I’m looking at the player script and there’s nothing in there to make it quick first frame.

Your areas do overlap with the floor. When they detect the overlap on the first frame, they check if the player is in group player, which is always true, so the game quits.

You want to check if the overlapping area is in group “player”, this script shouldn’t keep a player variable at all.

Add print(player) on each line above the quit()

You will find which node causes the quit() to run.

Could he do

If area == player:

No because player is constant in that script

Yeah I’d suggest you to change the quit with prints because debugging this is hell. And yeah, you’re checking if the player is in group player which should be true. Maybe you wanted to check if the body is player, or in group player? Either way, using the debugger (via the breakpoint keyword or using the debug tray) would be awesome here, especially to know which events fire and with which bodies