Here is my example code.
The result is that test and testArray variables are editable in the inspector. test is properly started with initial value in the constructor of Test class. But for testArray, when I edit array size in the inspector, the initial value of those variables are always system default. (p = 0, v = 0, c = Color.black) It isn't used the initial value in the constructor. I've already tried to define value in the declaration part but it doesn't help. Is there a way to work around this problem? This is just a test code. I intend to have many more editable variables in the class. Without initial value, it would be a pain to edit all of those variables again and again when increasing the array in the inspector.
asked Sep 09 '10 at 08:50 PM
Possible using the constructor:
Note: using the constructor for monobehaviours is usually a bad idea, but this is one place that it'll work well, as it'll create the array before the deserializer adds in any values. It will however mean that the array is assigned twice at runtime - You can however comment/remove the code before making a final build though
answered Sep 24 '10 at 03:10 PM
No. Array values must be initialized manually. If you have
That will initialize all of the values in the array. Unity does not do this for you, as far as I know.
answered Sep 09 '10 at 08:57 PM