- Home /
How to initialize array[][] via SerializedProperty?
I need to create an Array[][] of MyType from EditorScript and initialize it. But I have problems with serialization. MyType is serializable. In Monobehaviours script this operation very simple
var obj = new MyType[rows][]; for (int i = 0; i < rows; i++) { obj[i] = new MyType[columns]; }
But how can I do the same thing in EditorScript when I use SerializedProperty?
Answer by poday · May 15, 2013 at 10:51 AM
Unity's serialization doesn't support a multi-dimensional array (array[][]). See: http://docs.unity3d.com/Documentation/ScriptReference/Array.html towards the bottom "Note: Unity doesn't support serialization of a List of Lists, nor an Array of Arrays."
Since the serialization doesn't support it I'd doubt that their serialization classes would support it.
One possible workaround would be to flatten your array, instead of an array[x][y] you'd have array[x*y]