+1 vote

You can get all members of a group:

get_tree().get_nodes_in_group("group")

You can get all children:

get_children()

Is there a way to simply get specifically children that are in that group?
Is the only solution to get all children and then filter by their group?

in Engine by (20 points)

2 Answers

0 votes

I don't think there any single, built-in way to do that. I'd probably get the nodes in the group of interest and then get their children. So, something like this:

func _ready():
    for node in get_tree().get_nodes_in_group("the_group"):
        print(node.name)
        for child in node.get_children():
            print("   " + child.name)
by (10,914 points)
0 votes

Is the only solution to get all children and then filter by their group?

Yeah, or the other way around:

var children_in_group = []
for node in get_tree().get_nodes_in_group("the_group"):
    if is_a_parent_of(node):
        children_in_group.add(node)
by (1,094 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.