- Home /
The question is answered, right answer was accepted
Saving a ScriptableObject .asset on Android?
I have a strange issue and I feel like my step up is wrong somehow.
I'm using a ScriptableObject as an item shop, where a bool a checked if you purchased or owned one of the items. While I'm using the Unity Editor, when I run the game and purchase an item, the bool is saved on the .asset file and functions how I want it to.
However when I run the game on my Android device, the bool is checked until the application closes. When you restart the game, it resets to it's original state. How would I make this work on my Android device the same way it does in the editor?
Answer by liortal · Nov 19, 2014 at 08:46 PM
ScriptableObjects are objects that are not owned by game objects, and that can be serialized by Unity's built in serialization system as an asset.
Once loaded into memory (by calling ScriptableObject.CreateInstance), the data you store into this class will only be available at runtime.
AFAIK, Unity's serialization is only available inside the Editor, so you cannot take your ScriptableObject and store that to persistent storage while running on a device.
To achieve that, you can implement your own serialization system, or use the PlayerPrefs class.
Right, the ScriptableObject class is only useful for storing information at edit time. At runtime it's just an ordinary class instance which is initialized from the serialized data that has been stored at edit time.
Yep, found myself in the same trap :) Eventually, as far as I've figured out, there are lot of the appropriate solutions so as to save&store data and it's up to you which one to use. PlayerPrefs, JSON, Custom serialization etc. PlayerPrefs the easiest one, though. Thank you guys @liortal and @Bunny83 for the clarification!