0 votes

Hey guy's, I've been struggling a bit with getting a for loop going to get all child nodes which are buttons into a list. I can't figure out how to catch all child objects of a node, this is my code:

func on_option_buttonPressed(value):
for x in $ChooseGame/CC/PanelContainer/ChooseGameOptions:
    print(x.name)

Does anybody have any idea how to do this? ^^"

asked Dec 10, 2019 in Engine by voylin (15 points)

1 Answer

+1 vote
Best answer

You can get a node's children using Node.get_children():

https://docs.godotengine.org/en/latest/classes/class_node.html#class-node-method-get-children

This returns an array, which you can loop through:

for x in $SomeNode.get_children():
    print(x.name)
answered Dec 10, 2019 by kidscancode (13,084 points)
selected Dec 10, 2019 by voylin

Thank you so much, I was thinking about this the whole day already and now that I know the answer it sounds so logical ^^" I kind of feel a bit dumb right now for not thinking about that earlier.

Thanks again :D

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.