The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 votes

You can get all members of a group:


You can get all 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 (22 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"):
        for child in node.get_children():
            print("   " +
by (22,674 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):
by (1,254 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 Frequently asked questions and 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 [email protected] with your username.