Unity Editor locks up when initializing nested gameobject list


After a lot of messing with various things, the issue is NOT with this code, but with another chunk of code under it. I’m still not sure exactly what is the cause, but it is a separate issue.

I’m having an odd issue when it comes to initializing a nested list. Here is the code causing an issue.

Specifically, the last chunk that is commented out.

//Create a whole lot of values for the initial values of canPlaceTile & dirOfEntrance lists.
for (int i = 0; i <= minNumberOfTiles + 3; i++)
    canPlaceTile.Add(new List<bool?>());
    dirOfEntrance.Add(new List<string>());
    tileAtLocation.Add(new List<GameObject>());
    for (int b = 0; b <= minNumberOfTiles + 3; b++)
    for (int s = 0; s <= minNumberOfTiles + 3; s++)
    //for (int g = 0; g <= minNumberOfTiles + 3; g++)
    //    Debug.Log("Adding tile");
    //    tileAtLocation[i].Add(null);

A bit of explanation about what this code does:
This is a portion of code I’m using to create a randomly generated dungeon. To keep track of and test things I have a few nested lists that reference coordinates, like (0,0), (2,5), whatever and those are coordinates reference a specific tile so that I can do, say, “canPlaceTile[2][5]”, which would tell me if I can place a tile at location (2,5). But since I won’t necessarily place them in a nicely incrementing order, like (0,0), (1,0), (2,0), I just want to create all values as null so I can just reference the slot and not have to use .Add when changing values. So instead of “canPlaceTile[2].Add(true)”, I could just do “canPlaceTile[2][5] = true” to update the value from null to true.

Onto the specific problem:
The “tileAtLocation” list is a list of gameobjects so I can save the tile gameobject which has other info I need somewhere. Until I added the commented out chunk of code, the other two list initializations worked fine. However, when trying to do it for this nested gameobject list, I can start the game in the editor but when I press the button that causes this script to start the editor just freezes. No errors, no crashing, no logs, nothing.

When I comment these lines out, it runs fine until the code wants to reference tileAtLocation[0][0] and can’t because it isn’t initialized.

I thought maybe the for loop for it was the specific problem, so I created the single line above it just to see “tileAtLocation[i].Add(null);”. But it still froze. I thought maybe it doesn’t like adding nulls to a gameobject list, so I just made an empty gameobject and linked it to the script so it can try adding that instead. Still freezes.

I just tried this too, but moving the tileAtLocation out of the previously shown for loop:

Debug.Log("tileLocation Length = " + tileAtLocation.Count);

In this test, I removed the for loop just for tileAtLocation, but I still set the initial one of “tileAtLocation.Add(new List());”. In the first line of the above (if the second line isn’t included), it will return 29 as it should. So the first list is creating fine. However, the second line is what is causing it to lock up. When I try to do anything to the nested list it freezes, like it doesn’t understand how to access it or something.

I should mention, when this code runs as normal, another script is supposed to bring up a loading screen. When these lines are uncommented the loading screen doesn’t even show up. This script doesn’t even touch the loading screen at all, so I’m not sure why it wouldn’t be coming up other than the whole Editor freaking out for some reason and causing no code in any scripts to execute.

I also don’t see any spikes in CPU, Memory, Disk, or GPU usage in task manager and nothing is even near to maxing out.

Any ideas why this is happening only for this nested gameobject list and not the others?

It wasn’t even this code that was causing the issue.

It is something else, so this wasn’t the cause at all.