I'm trying to make enemies respawn at fixed locations across a level using a simple "enemy respawner" such that, if the player backtracks through the level, they will encounter the same enemies in the same locations, even if those enemies had been previously destroyed. The "respawner" scene is composed of a Node2D with a VisibilityNotifier2D as a child and has a script that looks like this:
extends Node2D
export (PackedScene) var Enemy
var enemy_spawned = false
func _process(_delta):
var enemy = Enemy.instance()
if $VisibilityNotifier2D.is_on_screen() and not enemy_spawned:
add_child(enemy)
enemy_spawned = true
if not $VisibilityNotifier2D.is_on_screen(): # <--- this line, here #
enemy_spawned = false
But obviously, the enemy continually respawns whether one is already there or not, so how do I check if that enemy has already been instantiated from that respawner?