Game Development Reference
In-Depth Information
Chapter 7. Creating
Save
and
Load
Systems
Saving data within a game is very important, which can be seen in just about every
game out there. There is all kinds of data that you might want to keep track of, not
only for yourself, but also for the player. The player's inventory, enemies' position, the
player's statistics, and a lot more can be saved and loaded from a file that you create.
In Unity, there are several ways to save data that you can choose from. Earlier in this
topic, we already went over how to use PlayerPrefs to save and load data. In this
chapter, you will learn how to use XML and custom flat files, and then create a way to
activate your saving and loading processes.
In this chapter, you will:
• Save data to a flat file
• Load data from a flat file
• Customize our flat file
• Save data to an XML file
• Load data from an XML file
• Implement a checkpoint-based system
• Implement an anywhere/anytime saving system
Saving data with flat files
The first and more common way to save data (that we will go over) is using the flat
file system. In this style, you can save a normal text file with data from your game and
load it later on. We will also discuss how to customize our file so that we can have our
own extension added to it. For our flat file system, we will save the player's position
as well as our statistics that we created earlier in this topic. To start off, we will need
to create a new C# script and name it FLAT_Save_System .
Adding the required variables
Before we start adding our variables and other code, we need to make sure that we
have all the required using statements. Add these using statements to your code:
Search WWH ::




Custom Search