- changed status to invalid
Two-dimensional arrays are not serialized in some cases
Hi.
I have a class where I serialize an array of a list of a custom class (List<ClassA>[ ]) and an array of such class (ClassA[ ]). The problem is that first collection (List<ClassA>[ ]) is serialized properly, but the second one is not.
I will attach two simple scripts which you can use to reproduce it. You add those scripts to a Unity project and then you create a (Serialized)ScriptableObject by (right-clicking in Project tab)>Create>Test>OdinTest. You will apprecite that collection1 (array) and collection2 (list) variables don’t serialize the two-dimensional integer array from the custom class, but the collection3 (two-dimensional array) and collection4 (array of list) variables serialize it properly. You can see the result here:
In the cases Odin doesn' show the testArray variable, it’s not stored in the ScriptableObject and the values are lost.
- I’m using Unity 2019.2.9f1 and Odin 2.1.4.
- Editor Only mode is disabled.
- I’m using Windows 10 Pro.
I found a work-around for the issue: I’ll use an array of size 1 of an array of my desired size so Odin will serialize it as a two-dimensional array, but I think it should work the other way too.
Comments (2)
-
-
reporter Oh, sorry, I understand now. Thank you for your quick reply!
Just in case someone needs something similar, the best solution seems to be adding the
[Sirenix.Serialization.OdinSerialize]
and[NonSerialized]
attributes to that variable, so it will be serialized just with Odin.Also, good job with Odin and its Serialization Debugger tool, really useful!
- Log in to comment
I'm afraid this isn't a bug, but Odin working exactly as expected and intended. You can confirm in the serialization debugger that this is the case - and you can find more information about why it is the case here.
Otherwise, thank you for an excellent issue report!
We really do appreciate it.