- Home /
My Scriptable Objects keep losing data due to a parsing error. How can I avoid this?
I have a series of scriptable-objects which I use to hold dialogue data. On these scriptable-objects I have a TextClass which holds the data of the text and potential branches, kind of like a tree, to other dialogues. Whenever I press Play, switch-scenes, edit a script, or even blink, I have to take a deep-breath that I don't get this error "Unable to parse file .asset: [Parser Failure at line 25: Expect ':' between key and value within mapping]". Has anyone encountered this, I greatly appreciate any help.
Answer by Andromedog · Jun 27, 2019 at 02:46 AM
So for anyone that is interested, I've come up with a thesis on the grand conundrum that is scriptable-object usage and instantiation:
Under the hood Unity does not serialize Scriptable Objects (SO's) as a transformative instance but rather a base-object with different key-value pairs (like a dictionary).
What this means is that if one were to try to refer to a non-native data-type such as a Class on a SO, unless the class is VERY simple, the class will be very volatile to resetting, as to create references to variables in the class would require ANOTHER key-value pair. Something that Unity does not support.
All in all that means, if you want to store-data on SO via class, you're better off not doing it. Rather you can put all the variables you want to change in that SO as native types (i.e. lists, int, bool).
OR
Make a class that derives from ScriptableObject.
It sucks, but due to the under-workings of Unity, there is no choice.
Now mind you that this is just a theory. I can be completely wrong on all of this, but I will test this method and a reply back on my results. Hopefully I don't lose data :p.