Making a UI menu loop while navigating

Minor question: so I have a simple menu, say the pause menu, where the user can use the keyboard to navigate through the entire list. When the user reaches the top/bottom, the navigation loops around, and they can keep searching the list. All is good.
My problem comes from trying to replicate this logic with a more dynamic menu of an unknown amount of buttons.
Will I have to manually set the navigation every time to keep it looping, i.e.

	Button topButton = buttons[0];
	Button bottomButton = buttons[buttons.Length - 1];
	// Set top-button
	Navigation topNav = new Navigation();
	topNav.mode = Navigation.Mode.Explicit;
	topNav.selectOnUp = bottomButton;
	topNav.selectOnLeft = bottomButton;
	topNav.selectOnRight = buttons[1];
	topNav.selectOnDown = buttons[1];
	topButton.navigation = topNav;
	// Set bottom-button
	Navigation botNav = new Navigation();
	botNav.mode = Navigation.Mode.Explicit;
	botNav.selectOnUp = buttons[buttons.Length - 2];
	botNav.selectOnLeft = buttons[buttons.Length - 2];
	botNav.selectOnRight = topButton;
	botNav.selectOnDown = topButton;
	bottomButton.navigation = botNav;

It’s not the worst but feels a bit messy, especially b/c I’m using object pooling so the menu order won’t always be consistent…so I was wondering if there was anything cleaner. Thanks!

Hey, I know it’s been a while, but I’m working at something similar where I have to set the navigation on dynamically created Selectables.

So far I’m pretty much using the same method as you. Creating an Array of the gameobjects and then using the indexes (isn’t Indizes the plural?), to change/correct their navigation selects.

I’m also looking for a more elegant solution but wanted to let you know you’re not alone.