







Data Persistence
March 2022
Typically, whenever the player enters a new scene, all previous information is deleted. However, we usually want certain information to carry on from the previous scene, like a player's name or score. This is the idea behind data persistence.
The purpose of this project was to code data persistence in between scenes, and then in between sessions (whenever the application is closed and then opened again).
Data Persistence between scenes:
Player name
-
The user is able to enter their name into the input field, which will then appear on the game screen. In Picture 1, Bobby enters his name. He then clicks "Start" and it appears in the left hand corner of the game (Picture 2). "You got this Bobby!"
Highest Score / Best Player
-
If the player makes scores a high score, their high score and their name appears on the menu. In Picture 3, Bobby scores 77 and beats the previous score of 47. Bobby clicks on the menu button and can see that he has the best score (Picture 4).
Data Persistence between sessions:
Highest Score/ Best Player
-
Upon starting the game, the previous high scorer is displayed below the title. In Picture 1, Player "Test" received a score of 47.
Methodology:
-
Between scenes
-
I created a game object / script called "Record Keeper" that utilizes a singleton to ensure it does not get destroyed upon moving to the next scene. It stores the Player name, the name of the Best Player, and the Highest Score.
-
-
Between sessions
-
I serialized the Best Player's name and their score using the JSON Format. First the data is saved. Next, the data is converted into JSON format and stored into a JSON file when the application is closed
-
When the application is opened up again, the data is data is converted back into its original classes and loaded.
-
Note: Completed as part of Unity's Jr. Programmer course and had to be submitted at the end of Mission 3. Coding for the brick breaking game and some of the UI elements was provided, but it was up to me to implement data persistence.
Note2: Unfortunately as this project uses JSON, it experiences bugs when converted to WEBGL format. This project works best through the Unity Editor.