Save byte[,,] in ScriptableObject

Hello,

First, sorry for my english (I’m French).

I work on a project for myself, and I have a question about ScriptableObject. I manipulate it for the first time (previously, I used “BinaryFormatter” to save my properties). I read carefully posts here

http://forum.unity3d.com/threads/serialization-best-practices-megapost.155352/

And this

http://www.jacobpennock.com/Blog/?p=670

I have a problem with my “public byte[,] data” (which is “serializefield”) inside a ScriptableObject. All of my value (string, int, etc.) are saved, except this byte[,].

I have a custom inspector to see each value on my asset (it’s like a debug), and everything is ok when I fill it, I have all of my values.

When my ScriptableObject go on OnEnable(), I see I lost all values in my byte[,], and other values like int, string, are always here. I use EditorUtility.SetDirty() to save all of my data.

I have an error message in console which told me “NullReferenceException: Object reference not set to an instance of an object” in the ScriptableObject when I try to make Debug.log(data[0,0,0]) in the OnEnable(). So I tried to make “data = new byte[x,y,z]”, and of course, the error left, but my data is empty now…

So, this is my question : Is it possible to save a byte[,] (and other array) inside a ScriptableObject ? (I haven’t find the answer on the first link. I saw a “List<>”, but I don’t want that)

If you have any others advices for ScriptableObject, I will be happy to hear you !

Thanks for your answer. If you need more informations, I will be happy to send it.

I’m not 100% sure what your issue is, but I remember having problems serializing multi-dimensional arrays. You can convert a byte[,] array into a byte array by using some clever indexing. Not sure this is the source of your problem, so I won’t mark it as an answer, but it’s worth a shot. Note you only need to do the conversion prior to serialization, if refactoring would be a huge pain.