0 votes

Hi ! I've been trying to make a loot that kills all the enemy in the scene when touched and i cant figure out how.
All my enemies are spawning from a spawner. they are all kinematicbodies2d.

Someone has some ideas or queue lines ...?

Thanks a lot !

Godot version 3.3
in Engine by (47 points)

1 Answer

+3 votes
Best answer

When you are instance()-ing and add_child()-ing your enemies also:

var new_enemy = enemy_scene.instance()

Then when you pick up that item you can:

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


get_tree().call_group("enemies", "die")

Replace die with whatever function you use to kill your enemies normally.

by (3,870 points)
selected by

Thank you so much, it works and I learned the concept of group !

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.