Multidimensional array will not keep items outside a loop

Hey all,

I have a 2D array which I am using to store menu items. This is how it works:

First a foreach loop sorts through multiple lists of items in a scroller. This is the y-axis.

A nested foreach loop assigns additional menu items inside these lists arranged in various sized rows. The x-axis.

This is what I am using to assign the items:

foreach(Transform child in scroller.transform)
{
	foreach(Transform button in child.transform)
	{
		menuList[x,y] = button.GetComponent<IsButton>();
		x++;
	}
	y++;
}

However, all items except [0, 0] register as null after the second loop. Printing out the name of [x,y] inside the nested loop results in the correct log.

Super weird. What am I doing wrong?

I think you should add x = 0; before foreach(Transform button in child.transform)