Im seeing this strange behaviour and cant seem to fix it. I have two arrays that I have initialized in script. Each having 43 elements within them.
This is how I am declaring and initializing them
[SerializeField]
private int[] missionSequence =
{
1, 2, 3, 4, 5, 1, 23, 25, 21, 6, 7,
8, 25, 4, 9, 10, 11, 12, 13, 14, 15,
10, 16, 17, 18, 19, 20, 21, 22, 24,
26, 27, 28, 29, 200, 201, 202,
203, 204, 205, 206, 208, 209
};
[SerializeField]
private string[] sceneNames =
{
"Green 1", "Green 2", "Green 3", "Green 4", "Green 5", "Red Defense 1", "Red 23", "Red 25", "Red 21", "Green 6", "Green 7",
"Green 8", "Red Defense 2", "Red Defense 3", "Green 9", "Green 10", "Green 11", "Green 12", "Green 13", "Green 14",
"Green 15", "Green Defense 1", "Green 16", "Green 17", "Green 18", "Green 19", "Red 20", "Red 21", "Red 22",
"Red 24", "Red 26", "Red 27", "Red 28", "Red 29", "Yellow 200", "Yellow 201", "Yellow 202",
"Yellow 203", "Yellow 204", "Yellow 206", "Yellow 207", "Yellow 208", "Yellow 209"
};
The problem is that these are not shown in editor. The int[ ] only reads 14 of the 43 elements and anything after that is null, whereas the string array is null from the start.
Debug.Log(sceneNames[0])
gives the error:
This is what the arrays look like in Unity (and when uploading screenshot I also noticed that the elements are in the wrong order)???:
I have tried every possible array initialization method mentioned in Arrays - C# reference | Microsoft Learn but I am getting the same problem.
Whats interesting is that if I change the name to missionSequence2
, and then save it works and shows all 43 elements, but after a couple minutes or after making any other changes to the script I get the same problem again with the renamed array also.
Is this a known bug? Has anyone else experienced this?
Im using Unity 2021.3.14f1