I have a node (root node of the main scene) that spawns enemies. When it spawns enemies it should delete all of its children that are enemies. To do this I have the following code:
# delete existing enemies
print(get_children())
for i in get_children():
if i.editor_description == "Enemy":
i.queue_free()
# create new enemies
for i in range(5):
var enemy = enemies.pick_random().instantiate()
call_deferred("add_child", enemy)
Creating new enemies works perfectly fine but get_children() returns every child except for the enemies. But when I look at the scene tree when running the game this is what I see:
But still, print(get_children()) only prints: [Player:<CharacterBody2D#29561455848>, Energy:<Label#29645341943>]
How can I get a list of all these enemies so that I can delete them when I need to spawn new ones?
Nevermind, I realized I was stupid and I wasn’t actually running the code at all! Thank you, I think this would have been a solution if there even was a problem in the first place