- Home /
c# array size doesn't grow past 10 (bracket initialization)
I have a singleton script, that all it does is handle / process arrays of names of layers, and then calls Physics.IgnoreLayerCollision on specific ones from specific lists.
The problem is, inside my script i have this array:
private string[] noSelfCollisions = {
"Team1",
"Team2",
"Team3",
"Team4",
"Team5",
"Team6",
"Team7",
"Team8",
"NPC",
"RTSUnit",
"Obstacles",
"Grid",
"Ground",
"Selectable",
"Default"
};
And then the inspector (even before I hit play) only shows the array until "Obstacles" and it's length as 10.
This is obviously wrong, and confuses me. The script has been recompiled, I have tried adding values and making the variable public, then private again (to force a recompile) but to no avail.
What could be causing this to happen? I'm confused to no end about this.
Are you sure noSelfCollisions is actually the array you're looking at in the inspector? I suspect it's something else, because private arrays are not serialized by default, so unless you have the [SerializeField] attribute directly above this declaration, it will not show in the editor.
Unity saves your actions, including values of variables. Just rename your array. Save it. And rename at original name once again and save.
If enabled "debug inspector" you can view private fields without having to serialize them.
zharik86 was correct and his answer solved my problem. The compiler in unity, for some wierd reason, was skipping this part of code as needing to be recompiled and used and old compiled version for this section.
Answer by 1337GameDev · Jan 14, 2015 at 05:22 PM
Unity saves your actions, including values of variables. Just rename your array. Save it. And rename at original name once again and save.
The user: agozharik86
This answer was correct. I thought changing values of the array would cause unity to retouch the array and compile it with new data, but you have to rename it. Something in it's compiler was stuck and would not recompile this part of code.
So in all, the problem is fixed, and for future reference to anybody, rename variables when they "stop" changing to have unity recompile them.
Answer by Berenger · Jan 14, 2015 at 08:16 AM
Something is messing with your array. Either you're not printing the correct one, or noSelfCollisions's value changes. Might be one of your scripts, or Unity (but the array was private to begin with, so it's probably not the issue). Initialize your array in Start or Awake, and print it right away, the values should be correct.
Try to find every affectation to this array in your code.
I thought it was being changed too, but that was not the case. The code was verbatim what i posted on a new script I created.
Your answer
Follow this Question
Related Questions
Problem with List not filling using add method in a foreach loop 1 Answer
Why ExecuteInEditMode Always Causes NullReferenceException Errors Even In Clamping!! 2 Answers
Object reference not set to an instance of an object error C# 1 Answer
Npc Quest System Array Error 0 Answers
error CS0236: A field initializer cannot reference the nonstatic field, method, or property 1 Answer