1. Home
  2. Docs
  3. Save Game Pro
  4. Tutorials
  5. Saving Data to Single File

Saving Data to Single File

Sometimes, we need to save a data only to single file instead of saving it to multiple files, as it makes the management of those files harder at scale, so in this case we need to use data wrappers and move our individual data to one single data wrapper and save all of them together.

There are many approaches to workaround this issue, and here we will point to the best approaches.

1 – Data Wrapper

Here is a simple example of Player data, such as position, score and health, at first we are saving all of this information individually to separated files:

Now, the below is using Data Wrapper approach to save the Player data to single file:

2 – Using ISavable Interface

ISavable is an interface provided by Save Game Pro to customize the serialization of a object by implementing the Save and Load methods, now here we will use the data wrapper example, but we will use ISavable interface instead of data wrapper approach:

You can also use C# ISerializable interface, but this interface is not available in UWP builds.

3 – Using Custom Type

You can make a custom type for the class you want to save it’s data, and handle the serialization of the data via that custom type and save the whole data in single file. (example is in development)
Check out our Creating Custom Type article for further information.

Bonus

We can save all of the player information in a sub-directory, this approach is similar to first state, but it just makes everything ordered and easier for further manipulations:

 

Was this article helpful to you? Yes 1 No 2

How can we help?