How to delete all nodes in group ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JokerDDZ

Hello.
Recently I created bullet hell and I have a problem with enemies. After I lost the game I dont know how to delete them all from the screen. I added all of them to the “enemy” group. Is there is any way to delete all nodes from the group ?

:bust_in_silhouette: Reply From: Xrayez

I think this should work:

for enemy in get_tree().get_nodes_in_group("enemy):
    enemy.queue_free()

You may want to remove enemies with remove_child() instead of deleting them in some scenarios.

There are other useful group methods that you can find in SceneTree (see docs).

Thank you for fast answer. It works for me :slight_smile:

JokerDDZ | 2018-07-23 14:41