- Home /
What is the best way to store and load data for a game with a large number (500) of small levels?
Making my first game. I have finally managed to get both JSON and binary de/serialization working to save/read the data needed to generate a level. Level data is mainly arrays of ints and bools with two structs. (An average level is 1.500 kB in binary and 10kB in JSON)
My game will hopefully have upwards of 500 small puzzle levels. Let's say 100 levels in each 5 catergory of very easy through very hard. What is the best way to store all this data? Do i make a file for each level and load the required level from file. Should i divide the files into directories for each category? Should I put all the level data into an array of levels and save that big array to file? Or something else completely. What is considered best practise or good/bad practice?
Note the data is only level initialising data. I don't need to save any progress level data other then level completed/incomplete which I can do in player prefs.
Answer by imrankhanswati · Nov 08, 2017 at 08:23 AM
Hi @whocaresitsmeokay :
As far as i know i would like to use one file and all levels in it because if you made too may "json" files unity will create too many "mata" file for them and also for you it will be difficult to manage (from management i mean searching file, updating file, finding errors etc ). But if their is just one file it will be easy to do update and finding errors. and also loading data form exterior file is little slow so if you have many files each for single level then you have to load data for each level form exterior file which will make your game slow. so if you have one file then you just have to load it one time may be at game start or some where else and use it. Also in future if want another level to add in game then you just have to update your levels file and you done.
Their another option called "Scriptable Objects" you can use them if want. Seem pretty good for your situation. https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects
Might this help... good luck. :)
Thanks for your advice Imran. Loading data for the level from a file on the fly needed doesn't seem to cause a noticable delay . As a check I made the scene reload the level from a file 1000 times and the delay was 1/2 a second. Yes I think one file to hold all levels will be easier then many small files. I can serialise an array of levels or a jagged array of levels sorted in categories. I just worry if deserialising >500 levels at once will cause a delay at startup. Plus I'm holding in memory all the data for every level which seems wasteful. I wastched the Scriptable Objects training video and though they seem powerful I don't think I would need them. They seem to be more for situations where a) many game objects reference the same data and b) where the programmer doesn't want to deal with file management and serialisation and wants to stick to reading data in using the familiar tool of references in the inspector. I have one game object using the level data. Since I have the file read and serialization already working I'll stick to that as is stated in the video link (51:30). This also means I can keep the level generation outside of Unity where I think it might be faster or easier. (Haven't got to that part yet).
I am going to leave the question open to get others opinions. $$anonymous$$aybe someone knows a simple way to have one file yet only deserialise the level needed.
Your answer
Follow this Question
Related Questions
What are the pros and cons of ScriptableObjects vs. JSON for data files? 2 Answers
Binary Serialization (In Editor) - Path Access denied / File not found 0 Answers
android serialization weird path issue " IsolatedStorageException ", javascript 0 Answers
Best practice to store and load a specific set of objects? 3 Answers