- Home /
Updating JSON game progress data after AssetBundle download
Hi,
I have a question regarding to a more client-server based game architecture.
I have a download manager that checkes the FTP if there are new versions, if so downloads the new assets in AssetBundle form and loads them.
Also, I have a game progress I keep them both in client and a DB server. I save the progress in JSON form at the client. I approach the solution by creating a Default Game Data JSON file at the first run that is generated from a ScriptableObject that holds all the default game data, say Level Names, Lock-Unlock info.
When the player first loads the game, the default JSON file is read and generated a new one to set progress data like lock-unlock by player's progress. However, I have a situation that, when I want to make a new update from FTP, I would be necessarily update the GameDefaults JSON and update the player's progress JSON to follow the game. But how would I do without violating the player's progress history and only add new fields in a proper way?
Answer by Bunny83 · Oct 25, 2017 at 02:09 PM
I'm a bit confused. AssetBundles can't contain scripts or new code (well it's possible to ship assemblies and load them manually). How exactly does an "update" look like? Do you have code in your main application that allows dynamically adding features without new code? Like new items with the same functionality but different look or stats? If that's the case you might just want to ship a "patch" JSON file which just contains the default values for the newly added item which simply get merged into the existing file.
How do you read / write your JSON file? Of course you can't use class mapping without actually changing the code as well.
So to properly answer this question we need to know more about:
How such an "update" might look like and what it can contain
How you read / write / manage your JSON data from code.
Hi,
I only ship new levels with bundles that hold the code assemblies with models. Levels are designed in the editor and bundled to FTP. All bundle info like version, bundle names served via an X$$anonymous$$L config file. So whenever the client runs the game, at the loading scene it checks the config file at the FTP, if the X$$anonymous$$L file has a higher version then the X$$anonymous$$L file at the client's storage, it starts to download related bundles and updates the local X$$anonymous$$L with the new version.
As you guessed I have the same functionality with new stats. Stats, textures are bundled and loaded from a ScriptableObject.
So I make updates whenever I make a new level design and each level has couple of new locked items where the player can progress.
When the player downloads and runs the game first time, after the download procedure I mentioned above, the Default Game Data is being created on JSON format. I create the JSON by passing the object inside JsonUtility.ToJson(data,true);
function, and read it with JsonUtility.FromJsonOverwrite(reader.ReadToEnd(), data);
So far, did not have blocking problems with the scenario above, also doing device tests on IOS but the problem is how to keep player progress data up-to-dated with updates.
I was thinking to generate another JSON file, name it Progress, a simpler one where it holds only booleans and sorted in the same order as the ID like Level 1-Stage 1, Stage 2, Stage 3.. since my levels and inner items are also sorted in the order from 0 to n . Whenever I do an update, the second JSON file will be overwritten with relevant data (mostly falses) and as the player does progress it would be set to true.
Sorry if I still did not manage to explain, but I trust your instincts that you will get it super correct :)