Now, I edit these values via my custom editor tool.
In the case of questionList, I can see these values in the inspector, and get saved ‘permanently’.
When I click away the editor tool and run the game, this list won’t get re-instantiated.
The values which were visible in the inspector will be used during run-time.
I want to do the exact same thing with the answerArrayList.
(In case you’re wondering… every question (variable amount) has three answers (set amount). So, every question has an string array)
However, these values (string arrays) do not show up in the inspector, and any values input via the tool get deleted when I run the application.
In other words: while the questionList (visible in inspector) does not get re-instantiated and keeps its values, the answerArrayList (not visible in inspector) DOES get re-instantiated and its set values deleted.
Hopefully I explained it clearly.
Thanks in advance for any help!
Unity is unable to serialize multidimensional collections. This includes any of List<List>, T[,], T[ ][ ] or in your case, List<T[ ]>.
There’s two ways around this:
Solve this in some other way that doesn’t require a multidimensional collection. If you create a [Serializeable] class Answer, which contains either a list of strings (or just some string-fields if the number of answers is the same for any question), you can use a List of that.
Implement the ISerializationCallbackReceiver interface. When Unity is serializing and deserializing your classes, and finds that interface, the OnBeforeSerialize and OnAfterDeserialize methods gets called. You would then use this to “flatten” your answerArrayList into a single, one-dimensional array before it gets serialized, and then restore it to a two-dimensional array after it gets deserialized.
The first option is the easiest one, and it’s probable that you’ll end up wanting an Answer class anyway, so I’d go with that. At the same time, knowing your way around ISerializationCallbackReceiver will get necessary at one point if you’re developing in Unity, so this might be the time to learn to use it if you haven’t already.