public void GenButtons() { int[] tempStats; AvailableHeros.Clear(); HeroesChosen.Clear(); //populate available heros who match the tier requirements AvailableHeros = CharectorStats.heroesThatCanBeSacrificed(heroRequirements.heroType, heroRequirements.stars); if (gridButtons.Count > 0) { foreach (GameObject button in gridButtons) { Destroy(button.gameObject); } gridButtons.Clear(); } for (int i = 0; i < AvailableHeros.Count; i++) { tempStats = CharectorStats.UnlockedCharector(AvailableHeros[i]); GameObject button = Instantiate(buttonTemplate) as GameObject; gridButtons.Add(button); button.SetActive(true); button.GetComponent <TileListButton>().SetText(CharectorStats.HeroName(tempStats[1])); button.GetComponent <TileListButton>().SetSacrificeIndex(i, tempStats[0]);//also sets toggle functionality and backpackindex to the button button.transform.SetParent(buttonTemplate.transform.parent, false); } }