Accessing Nodes from Array Created via get_children

Godot Version

4.2.1stable

Question

Can’t for the life of me figure this one out. I’ve made an array called grid.

var grid:Array

No Issues. Then I use get_children to populate that array from the node running this whole script.

grid.fill(null)
for i in self.get_children():
    grid[#calculated_index] = i

I can print(grid) and it will give me Node references, but not the names corresponding to the hierarchy. It also won’t let me affect the nodes from the grid e.g.

grid[0].position.y += 5

Does nothing. I could easily do this in unity, but I’m trying to switch to Godot. Liking a lot of it, but this is so frustrating. Any help is appreciated.

just use i to access the children

oh yeah, grid.append(i) first
either you fill the grid array with zeros first so then to access it like grid[#calculated_index] = i
or append like that

I am filling null before. I edited the original post to show. I can’t really append though because I need it at a specific index. I’ve tried insert and this current = method. Same results.

The problem persists though that using
grid[0].position or .anything
still produces no results

then it’s possibly be you get children where the children havent yet added as child for this node

what node type is the children btw?

All the children are Node3D.

to get the node name, try:

for the_node in grid:
    print(the_node.name)

I can do that, but if I do something like
node.name = 'garbage'
then print again. The node shows garbage as the name but it hasnt changed the name of the node in the hierarchy.
Seems like a reference issue. How can I get the children of a node into an array that I can use to later access those nodes and affect them?

image
it was from “asd” name

get_children() already be giving you all the reference to all the children it has

at when you try to set the position value? at _ready()?

_process(delta)