- Home /
Upgrades system using Scriptable Object, losing data when renaming a variable
Hey guys.
I made a simple upgrade system for my game, and I am happy with how it works, however the game is in development and things change all the time. Each time I rename a variable in my Upgrades Scriptable Object class - the data gets lost and I have to put all the values again. Is there any better approach to store data like that during development?
Thanks.
Don't change the names of variables that have already been serialized. Na$$anonymous$$g is too important for serialization, it is by name how serializers find and assign data, changing those names when data has already been serialized with a different name is obviously problematic. So the best advice in this case is to sit down and decide the appropriate names for the classes and their variables that you will be making scriptable objects out of and try to never change them
.
If you will continue to work with scriptable objects that is all you can do. Your other option is to dump scriptable objects altogether and make your own serialization system, with a custom editor window to view/modify your custom data types and hook some temporary methods into whatever serialization library you use so it can handle name changes in your data types
.
Regards
Edit: Disregard everything I said. I learn something new everyday. I know nothing. Praise @Prastiwar
Well, anyway thank you for your effort and exhausting answer. There is always something to learn. ;)
Answer by Prastiwar · May 08, 2018 at 06:23 PM
You can use FormerlySerializedAsAttribute Examples are on old blog. https://blogs.unity3d.com/2015/02/03/renaming-serialized-fields/
Your answer
Follow this Question
Related Questions
Are ScriptableObjects good for non-visualised models? 2 Answers
How to access TreeData 1 Answer
"Prefabs" for classes, scriptableobjects? 2 Answers
Scriptable Objects as a datatable 1 Answer
ScriptableObject Inheritance 1 Answer