+1 vote

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 ?

in Engine by (53 points)

1 Answer

+2 votes
Best answer

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).

by (1,356 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.