public void PopulateItems(InventoryList inventoryList) { // don't want to modify the list in place, instead copy and iterate through that // it Just Works foreach (Transform oldItem in gridHolder.transform.Cast <Transform>().ToArray()) { // Destroy is called after the Update loop, which screws up the first child selection logic // so we do this so it's not shown Destroy(oldItem.gameObject); oldItem.SetParent(null, false); } List <StoredItem> items = inventoryList.GetAll(); for (int i = items.Count - 1; i >= 0; i--) { StoredItem storedItem = items[i]; GameObject g = Instantiate( itemPaneTemplate, Vector2.zero, Quaternion.identity, gridHolder ); g.GetComponent <ItemPane>().PopulateSelfInfo(storedItem); } gridHolder.GetComponent <SelectFirstChild>().OnEnable(); }