Get_children confusion

Godot Version

4.3

Question

I have my code properly running with this:

var arr = []
for x in some_node.get_children():
arr.append(x)

but instead of a for loop, i need individually add nodes in the array, so i do this:

var arr = []
arr.append($node1/node_one)
arr.append($node2/node_two)

As simple as i thought it would be, my code breaks at this point.

It has something to do with “get_node fetches the node by NodePath” and get_children returns an array.

But i cant figure it out. I get all the child nodes from a parent node with get_children() and append them into the array. Where is the “returned array by get_children()” here?

How to get the same result by adding nodes individually without the loop and get_children? I need help

Is the same as

var arr = some_node.get_children()

Because get_children() returns an Array of all the children, it does not need to be added to an array, it already is one.

1 Like

What am I missing here?
Both his code samples as shown (apart from the missing indent) should work.

1 Like

@gertkeno
im trying to avoid get_children()

@sancho2
thats what i also thought but its not the case. If you further utilize the values, the outcome is different. Although if you print out the arrays, you get the same result, which confuses me and makes it hard to understand.

edit: i figured it out, the issue wasnt with get_children()