Need help converting a SelectionGrid to new UI

I had a script in the old UI that sort of looked like this: (example code is somewhat simplified for clarity)

public GameObject[] things;
int selectionIndex;
string[] content;
void Start(){
 content = new string[things.length];
 for(int i = 0; i < things.length; i++){
  content _= things*.name;*_


void OnGUI(){
selectionIndex = GUI.SelectionGrid(new Rect(location), selectionIndex, content, 2);
if(GUI.Button(new Rect(location), “Make selected thing”)) MakeAThing();

void MakeAThing(){
Instantiate(things[selectionIndex],, Quaternion.identity);
So, in the new UI, getting a button to call that function is easy enough. But, how do I set the selectionIndex? I could make a ToggleGroup and add Toggles, and give them an OnClick event that calls a method that sets an index value tied to that toggle…
Added complication then is that the size of the things[] is variable, so I’d have to somehow set the value of the int set by the event call on the Toggle… (and create the toggle game objects dynamically, but that’s not really an issue)
Well, it seems like it would be really complicated compared to the old way of doing things, and right now it feels like just using the old method is a better idea than trying to make it work with the new UI. So, is it? Or have I missed something about the new UI system that gives me a reasonable way of doing this?

I’d create a prefab from a Button that also contains a script attached which stores reference to a GameObject (lets say that reference is called “thing”).

When you have to add the buttons on the grid, instantiate that prefab, get the script component and set the game object reference to the thing it must instantiate when pressed. You’ll be iterating over the “things” array, so you have the thing there.

Set the On Click event of the Button to call an OnClick method defined on the script, and inside that method call:

Instantiate(thing,, Quaternion.identity);

To get the buttons displayed on a grid use de “Grid Layout Group” component on a game object, and when you instantiate the buttons, make them childs of that game object.