- Home /
Save data collection to local database?
Problem: My script generates 4 objects with a semi-random position and rotation when the scene is loaded. I want to be able to save the position and rotation of these objects to some sort of database. Not all generations will work for my game. So I want to generate them and save the ones that work to be randomly selected and used when the scene is loaded.
Can anyone point in me in the right direction to what might be the easiest way to implement this? I don't think PlayerPrefs is the way to go. I will likely store around 1,000 of these data collections.
Thank you!
There are several different options the most common ones would be :
Unity's Serializer, preferably when the data are directly supported and the generation happens on edit mode.
C# Serializer decent all around solution.
Json via JsonUtility class.
Use of external DataBase (ex. sqlite)
Its one has its cons and pros but the first three are fit for your needs, don't bother with the last one. Regardless of using them make sure to learn about the Unity's and C# serializers. As for including them on a build check out Strea$$anonymous$$gAssets/ Resources special folders for anything apart the first solution which can directly create a ScriptableObject that can reside anywhere inside the Assets and be included (as long it is referenced inside any Scene). Search on what is included in the Build for more info.
Cheers.
Answer by Trevdevs · Jun 24, 2018 at 11:55 PM
If you don't want to use playerprefs you gonna need to do object serialization.
https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
Great thanks! I guess I worded this a little off. Do you know if its possible to package this file with the game? I actually need to write the file in development, to be loaded and used in the final build.
I got it all figured out. This was the final piece to answer my question... https://docs.unity3d.com/$$anonymous$$anual/class-TextAsset.html
You can load binary data in as a text asset.
Thank you!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Remote database for leaderboard 2 Answers
Which Database Should i use?,How i can use database? 1 Answer