How to add nodes to a group in version 2.1 - many nodes at once

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Brinux
:warning: Old Version Published before Godot 3 was released.

Greetings,
In Godot 2.1, putting nodes into a group is radically changed, and the new process is not in the documentation - however, I found an answer here:
https://forum.godotengine.org/7039/missing-features-of-ui?show=7039#q7039
BUT that leaves me with
THE QUESTION: How can I add multiple nodes to the same group all at once?

:bust_in_silhouette: Reply From: avencherus

Doesn’t look like there is a way to select them all and add them all via the editor GUI. So if you want some rapid way of creating groups, you may want to manage it at runtime in script.

For example inside a parent node, say you want all it’s children to be grouped you could write something simple like this:

for child in get_children():
	child.add_to_group("my_group")
	
print(get_tree().get_nodes_in_group("my_group"))

You will find group methods in the SceneTree: SceneTree — Godot Engine (stable) documentation in English

Nice idea, I did this manually recently and wish I’d thought of that. Will try and remember for next time I’m grouping heaps of items.

Robster | 2016-10-26 05:08