- Home /
Serializing Dictionary: Data lost between sessions
Hello all,
So I have myself a ScriptableObject that save in my assets and want to use as a prefab. In this object I have a Dictionary. As you may know Unity does not serialize Dictionaries, but lucky for us in 4.5 they gave us these handy little methods, and even luckier for me the example they gave is supposed to do exactly what I need.
I copy those example methods and viola! They work like a charm... Until I close and reopen Unity... Data persists in my current session, but when I close and reopen Unity all of my data is lost. After spending hours searching for a working fix I'm pretty much at the end of my rope here. How can I fix this?
UPDATE: Upon further mucking about with this, I think I have narrowed the problem down to my editor script. Basically, among other things, I replaced the Dictionary<> with a List<>, which Unity DOES serialize. However, with my editor script enabled the problem persists. When I disable my editor script and use the default inspector, I can still see all of my data in the inspector and the problem does not occur.
My fixed code that uses a List <-- Using this script without a custom editor has no issues, but it's a not-so-ideal implementation IMO
Easier to help if you post your code (or at least an example we can use).
At a glance, I'd check to make sure those key/value lists are being serialized in the first place. Are they visible in the inspector?
Added my code to the original post. "Are they visible in the inspector" is kind of hard to answer, cause I had to write a custom editor script for it. But as I said earlier, all data appears to be serialized properly in the current session of Unity. All data persists between edit and play mode, after scripts are complied, etc.