How to delete nodes in group instantiated in scene tree

Godot Version

<stable4.2>

Question

<Im managing enemy spawning by making ObjSpawner scene which basically instantiate assigned enemy object when attached VisibilityNotifer entered camera. Id like to queue_free them when player left the room and respawn them when reentered in room, just like in metroidvania game. To achieve this, I tried to queue_free enemy nodes by connecting the signal area_exited of the room to ObjSpawner. However, I have no idea how to queue free "get_tree().get_nodes_in_group("Enemy")". So I would appreciate if you could teach me how to queue free nodes in group.

Even if this works, I kinda feel it is too much work to connect signal of all room to ObjSpanwer. Do you have any better idea to make this work?

for i in get_tree().get_nodes_in_group("Enemy"):
     i.queue_free()

This should work.

I would just add a timer for maybe 10 seconds, and when it expires, just make sure that the enemy is still off the screen before you queue it free

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.