How do you clear a group?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

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?

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.

Ertain | 2020-07-12 06:25

:bust_in_silhouette: Reply From: dustin
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!