- Home /
Array of arrays = No serialization?
The docs say Unity doesn't support serialization of an array of arrays... So I can't save such data?
How about... a Hashtable of hashtables?
Answer by thorbrian · Dec 01, 2011 at 06:30 PM
Just do an array of objects with an array in them, and Unity will serialize that and be able to show it in the editor just fine:
public class ThingWithArraysOfArrays : ScriptableObject
{
[System.Serializable]
public class ThingWithArrays
{
public int[] array;
}
public ThingWithArrays[] array;
}
that will solve your serialization problem at the cost of accessing the nested array like: container.array[x].array[y] instead of container.array[x][y], but if that's a problem, you could try adding an overload of the [] operator to the ThingWithArrays like this:
public int this[int i]
{
get
{
return array[i];
}
set
{
array[i] = value;
}
}
... and if you are using javascript instead of C#, well sorry.
Answer by Jesse Anders · Nov 25, 2010 at 12:32 PM
Usually there are ways to get around the limitations of Unity's serialization system. One option in your case might be to create a serializable custom class that has an array as a member, and then create an array whose element type is that class (I think this would work, but I'd have to try it to be sure). If you're just wanting a (square) 2-d array, another option would be to store the data as a 1-d array and provide accessors that support 2-d indexing.
So having an array linking to GameObjects that are storing another array will work just fine?
I'm not quite sure what you mean, but regardless, an effective way to find out would be just to try it :)
Answer by legopatch · Dec 01, 2011 at 05:10 PM
I used a hashtable of hashtables to save the objects in my project, using the propertylist serializer on the wiki.
for it to work though I had to have an array that stored the name of each sub hash table, that way I would know what to iterate through.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084440im_/https://answers.unity.com/themes/thub/images/avi.jpg)