Public Arrays reset themselves
In order to get an array variable from another scrip I need to make the array variable public. When you made an array variable public you can see it and chance it from the Insecptor (directly from the editor). It seems that Unity switches to Inspector settings of array. So by default all arrays set at 0. And when I launching my game Unity ignores code like "public int[] damage = new public int[4]" and does like "public int[] damage = new public int[0]". I can fix that by REdeclaring a variable from the function in code but it doesn't looks professionally and it's superfluous actions.
Is there thing that can make unity ignore Inspector settings of public array?
Answer by NicholasSheehan · Mar 23, 2017 at 01:03 PM
you can put the attribute [HideInInspector]
above the array and it shouldn't be edited by Unity
Edit: That doesn't work like i thought it did, testing stuff now
Edit2: you should be able to use internal
instead of public
and be able to pass the array over scripts, but not allow unity to overwrite them.
Just tested it out. Works fine! Thank you very much. $$anonymous$$aking a variable Internal solves the problem.