- Edited
I have a couple of level scenes and each scene has a bunch of enemies. These enemies can be killed and I want to keep
check if an enemy is dead or not and use that when the level scene is loaded. Ideally, when an enemy is defeated I want to store the enemy position and display the corpse there when the level is loaded.
I know that I need to use a singleton to store data globally so my idea has been to create a global script with a list, I called that dead_monsters and whenever one has been killed I add the instance to it. The code for the logic is this:
global
var dead_monsters = []
enemy
func death_logic():
Global.dead_monsters.append(self)
level
func _ready():
for enemy in $Main/Enemies.get_children():
if enemy in Global.dead_monsters:
enemy.dead = true
This doesn't work, I think because the enemy instances are freed whenever the scene is changed. What is the best way to get around that?