0 votes

Hi All. I thought clearing a group would be as simple as using get_tree().get_nodes_in_group("mygroup").clear(). But when I do that and print the group after that, it still prints out all the items... How do you quickly empty a group without looping through it and removing items one by one?

in Engine by (396 points)

AFAIK, there isn't a way to easily remove a group of nodes without going through the group via get_nodes_in_group("mygroup") and freeing the individual nodes.

1 Answer

0 votes
for nodes in get_tree().get_nodes_in_group("mygroup"):
   nodes.remove_from_group("mygroup")

this goes through all nodes with the group "mygroup" and removes it for that group. hope this helps!

by (439 points)
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.