I am simply trying to keep track of player positions and load relevant cells, however when I run the code it hangs/infLoops, and I can’t for the life of me figure out why. When I run the code with a Debug.Log it runs fine, but as soon as I re-enable the list.add() it freezes up. Any idea what could be the issue?
void UpdateRequiredCells()
{
AllRequiredCells = ActiveCells;
for(int c = 0; c < ActiveCells.Count; c++)
{
for(int x = ActiveCells[c].x - SpawnRange; x < ActiveCells[c].x + SpawnRange; x++)
{
for(int y = ActiveCells[c].y - SpawnRange; y < ActiveCells[c].y + SpawnRange; y++)
{
if( !AllRequiredCells.Contains( new Vector2Int(x, y) ) )
{
Debug.Log($"{x}, {y}");
//AllRequiredCells.Add(new Vector2Int(x, y));
}
}
}
}
}
The console displays all the relevant cell ID’s when run, but the AllRequiredCells.Add(xy) is causing the engine to hang/freeze. I tried adding a bool that activates to prevent a new update from starting it over and clearing it out prematurely, but it had no effect. Not really sure what’s the problem here.