Having an issue that has me stumped.
Update()
{
CycleList();
}
void CycleList()
{
for(int i = list.Count - 1; i >= 0; i- -)
{
Destroy(list[i]);
list.RemoveAt(i);
}
list.add(something);
list.add(something);
list.add(something);
}
This is causing the list to eventually throw a missing reference error to the list itself, and causing the list in the inspector to constantly flash, as though the inspector is updating after all the list items are being destroyed, even with the remove call directly after. Adding a list.Clear()
after does not fix the issue. Even pooling the gameobjects into another list, removing them individually or clearing from the current, and destroying items in the other list later in update does not fix the issue.
Edit 1:
I have switch over to pooling after some more testing. Adding a secondary list with a delay on the destroy function started causing the referenced gameobjects to build up in the hierarchy and not get destroyed. Since this is happening every frame, it would quickly build up and ruin frame rate. After adding a booling check so I could stop adding new items, and maybe let the the destroy list w/ its delay catch up, activating the bool would throw errors referencing destroylist.array['index here'].data
missing and an unsupported pptr value error. It seems to be related to a bug that was assumed resolved in 2022.2
(I am using 2022.3.0
for this project). I will leave this up as unanswered as I could not find a confirmation that this was indeed the issue, and if it is not, I am still looking to find out the reasoning behind it for future reference.