0 votes

I have several nodes in a group and I want to delete them by code only those that are within that group, i know how delete childrens with:

 for i in get_children():
    remove_children(i)

How do I do them for the nodes that belong to the group?

in Engine by (183 points)

2 Answers

0 votes

You can check if the node is inside the group with this method: Node.is_in_group

by (90 points)
+2 votes

You could do something like:

for node in get_tree().get_nodes_in_group("enemies"):
    // do something with this enemy node
by (10,894 points)
edited by
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.