Save gameobjects in a list before destoying
So i'm trying to save all inventory slots from a loot box before destroying them when they are not being displayed anymore. I want to use the exact same UI gameobject for all loot boxes that is why I want to destroy the slots after they have been displayed. I realized that just by putting the the slots gameobject into a list want help because they are destroyed which means I can't access them anymore. Is there an easier way to save the slots instead of making all of them to new prefabs and save the prefabs in the list? I want to save the whole slot to save the item with it's item icon, amount, item ID, item name and item description.
This is my code saving the slots (which wont work they I want my system to work):
public void CloseLoot(Transform _player, Transform _UI)
{
lootSlots.Clear();
for (int i = 0; i < _UI.GetChild(1).GetChild(0).GetChild(0).childCount; i++)
{
lootSlots.Add(_UI.GetChild(1).GetChild(0).GetChild(0).GetChild(i));
Destroy(_UI.GetChild(1).GetChild(0).GetChild(0).GetChild(i).gameObject);
}
}
So how would this void look if I want to save the slots more permanent after destroying the original?