top of page

Data Persistence

Starting Date: 23/05/2025

Ending Date: 04/06/2025

This blog is about adding save and load data to the game in order for the players to resume to existing games that aren't completed yet.

Objective

The goal of this blog is to create suitable data persistence that can allow the player to save the game and when they quit the game they can resume back to the existing game with all the data included such as their position, statistics, resources obtained, effects and possibly their abilities (if they're required).

​

The first objective is to create data classes that can be used to retrieve the classes to change the value as well as saving new values, this will involve classes that can be accessible to other scripts which those scripts will have two methods one for storing and one for retrieving the data classes to change certain values.

​

The second objective it to provide data systems that can allow those scripts to call methods that will get and set the data, this will involve a class that is globally accessible to call all of the methods to load, save and even delete data.

Techniques

Json Serialisation & Deserialisation

Json serialisation is a data file that converts a object into suitable data, meaning that certain classes can convert their variables into suitable data type. Deserialisation is the opposite which converts a Json file values into variables that can be used in a script. Json files can only store integer, string and float variables.

​​

I use json files to provide a method to store character data, player data, game data and other ability data such as stance data for double wielder, ruthless data for robotic superstar and both luck and lucky data for both of lucky gambler's abilities.

​

This was useful to me because all the data that I have mentioned are able to serialise into a json file when saving the game and then deserialise into unity variables to be used to change the behaviour of the game, this leads the player to return back where they're left off.​

Static Classes

Static classes are a unique behaviour to implement onto a class which makes the class globally accessible without being added onto a component of a object. Meaning that class can be reference without being added onto an object.

​

I use static classes to create data systems which other scripts can call one of the three methods: Store, which saves the data as a serialised json file. Retrieve, that checks if there is a data file following a data persistent path to locate in the player's device which loads the data to the script to use. And delete, which deletes the existing data.

​

This becomes useful for the player to save and load their game to return to later, however it is also important for the player to create a new game if they want to play a new session instead of the current, which leads the player to choose to either carry on or play a new game.

Challenges

Unable to Understand for a While

Originally, this task was supposed to start and finished on the third month of the project's life cycle (April) in order to save and load data in the game, however a massive issue with me was that I didn't fully understand implementing data persistence, this is because of my lack of knowledge of how persistent data paths function in a device and when researching tutorial they weren't as helpful as I thought they would be.

​

Although this was complete before the deadline of the project, this could have been completed sooner if I had better understanding towards data persistence based on knowledge and design structure, which lead me to scrap some ideas during May.​

Achieved

Data Persistence Complete

Data persistence was completed by creating a data class and system for other scripts in the main menu, character selection and the board map itself to store, retrieve and delete data. Saving the game occurs when the player's turn is complete, loading the game occurs when the player chooses load game in main menu and deleting the game occurs when the player chooses new game.

​

This becomes very useful if the player wasn't able to finish the game on their first session, this is because the game can be long in some occasions, meaning that using data persistence to save and load data will allow the player to return the game where they've left off, which leads players able to finish their game during multiple sessions.

Conclusion

Overall, I have learnt how to create save and load data in the game, while there might be some data that should  be added into the game such as the start of the turn to keep the movement and status cards the same, this was quite successful in my project to allow the player to carry on with their session.

​

As a programmer, I feel like I need to learn about the structure and the requirements of adding data because I feel like I can implement a suitable data system to store, retrieve and delete, I need to figure out what variables and values in my game should be stored to keep the experience completely the same such drawing cards on the turn or certain item behaviours such as the vacuum which can randomly steal mana from the opponent.

​

For me, if the project that I am creating takes one session at its longest more than 10 minutes, then I should consider adding data persistence to the game in order to allow the player to return to their sessions in order to finish the game.

bottom of page