The question is answered, right answer was accepted
Changes for array not recognized on start
Hello everyone,
i have a very strange issue. I have a int array declared in my class. It looks like the following:
public int[] test = { 1, 2, 3, 4, 5, 6 };
So i can run the game and the array is properly initiated.
Now, if i close the game, change a value in the array, for example it looks like this now:
public int[] test = { 2, 2, 3, 4, 5, 6 };
I debug the game and look into the array and it still looks like this:
public int[] test = { 1, 2, 3, 4, 5, 6 };
So nothing has changed. I make sure that i was saving the file und rebuild it, but it is always the same outcome.
The only way i can fix this, is to comment this line out, start the game, stop it, uncomment it and then start it again. After this the change is been recognized. Don't know what i'm doing wrong there, but this doesn't seems to be a normal behaviour for me. Any idea?
EDIT As addition i initialize this array outside of the Start() method.
Thanks!
Answer by btmedia14 · Jun 16, 2016 at 05:44 PM
When looking into the array during debug be certain it is the value you are seeing and not the index value of the array itself, although index values run 0 to 5.
The test[] variable is declared as public so it is accessible in the Unity inspector. The inspector allows values to be specified that override the script declaration - useful for quick debugging and testing. Verify that values appearing in inspector for the test array are as expected.
Not sure how commenting/uncommenting declaration is giving behaviour seen.
Ah i see, that was exactly the issue. The values in the inspector are the old ones and they override my changes in the script, because they were not updated. I wasn't aware of this. Thank you for the hint!