Freeing the Area2Ds on multiple identical nodes (not instantiated with code)

Godot Version



Specifically, I have a node that acts as a spawn point for the player. I’m only deleting the Area2D attached to it for…reasons, but if I put two of these in a room only the one the player spawns out of will lose its Area2D.

Relevant Code (The Spawner):

@onready var loadPlayer = load("res://scenes/player/player.tscn")
@onready var player : Player = loadPlayer.instantiate()

func _ready() -> void:

func _on_area_2d_area_entered(area: Area2D) -> void:
	if area.is_in_group("Player"):

I get that multiple spawners are treated independently, but my attempts at deleting them with groups in even global scripts haven’t worked so far.

You code is telling a specific area2d to be deleted, in this case the one that sits in the tree at path “$Area2D”, so why would any other area be deleted?

Side question: what is your setup that you add player as child of a spawn point? I can’t think of any scenario where this would be a good thing to do, but ofc maybe I am just not understanding. Spawns mark where player should spawn, but they should not be parent of Player.

Only your Level node should be parent of Player. Then Level would have a Node called SpawnPoints, which has as children a collection of Node2Ds (or custom class that inherits from Node2D) that are your spawns. When player spawns, go through every child of SpawnPoints node and disable the area2d you’ve mentioned. At least from very limited provided info this is how I imagine the solution to be.

I was trying to get away with not having a script for the root node, but the spawner being the player’s parent is what was screwing me.
That and the fact that I was running the wrong scene and couldn’t figure out why I was getting null instance errors. Thanks.