I assume you want to assign the focus to prevent neighbor-ing out of the grid container, you could set the neighbor to itself so it doesn’t move past the button
for i in $GridContainer.get_child_count():
var is_top: bool = i < $GridContainer.columns
var is_left: bool = (i % $GridContainer.columns) == 0
var child: Control = $GridContainer.get_child(i)
if is_top:
child.focus_neighbor_top = child.get_path()
if is_left:
child.focus_neighbor_left = child.get_path()
Wait - staring at this, I realised that I forgot that I have to go one step deeper in the code to fetch the button of my child node. Now it works perfectly!
Thank you so much! This is so much more simple and elegant than what I was trying to do.