This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

I want that in certain moment all enemies (Which are in a group) get deleted.
I could create a global variable and detect it from the enemy script.
So when it changes it deletes the enemy.

But is there any easier way to delete all objects in a group (All objects are instances of a scene using the preload method) ?

in Engine by (131 points)
edited by

2 Answers

+6 votes
Best answer
var enemies = get_tree().get_nodes_in_group("enemies")
for enemy in enemies:
by (29,510 points)
selected by

Thanks for answering :)

+6 votes

call_group may help


Or use the enemies delete/kill method if you need to do something else instead of free directly.

Documentation about groups:


by (7,954 points)

This should definitely be the accepted answer.

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 Frequently asked questions and 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 [email protected] with your username.