Save Manager

The Save Manager is designed for beginners as well as veteran developers. The asset allows you to save most common datatypes into a local file which can be loaded at your convenience.

Documentation

Summary

Introduction

Firstly, thank you for deciding to use our asset for your project. If you like our asset, feel free to leave us a review! If you find that our asset is not up to scratch or find and issue please do let us know either via our email: support@carter.games and we will do our best to help you with the issues you are facing.

Supported platforms

The save manager supports all platforms that support binary file saving. However, we DO NOT support WebGL saving in this asset. This is purely due to the end user needing to have a webserver to host parts of the asset as well as it being rather complex for new users, which this asset is more geared towards as a target audience.

Install

Getting Started

Installing the asset is super simple. If your using an older version of Unity you will be able to get the asset from the asset store within Unity. However if your on a newer version then the asset can be installed via the package manager under the My Assets section. Once imported into the project, you’ll be ready to use the asset.

Install

Setup

The setup for the asset is very straight forward as there is a handy editor tool to do all the hard work for you. The tool assists in the creation of the SaveData.cs file which a blank version of is provided with the asset to avoid errors in the package. Now you can just write in the file yourself if you know what you are doing and put in your save types.

⚠️ Editing the class yourself has the risk of breaking the editor tool, we have tried to catch all issues, but you may experience issues by editing the class yourself.

Accessing the editor tool

To access the editor tool, all you have to do is navigate to the tools tab on the navigation bar at the top of the Unity window and enter the Save Manager | CG tab and press the Save Data Editor option. Once pressed an editor window will popup which can be moved, resized and docked as you would with any other tab like the inspector, hierarchy and game view tabs for instance.

How to use the editor tool

The editor tool comprises of 2 main tabs, the first one allows you to create and edit the Save Data class with and the second display information about the asset as well as useful links relevant to the asset. When opening the tool, if you already have an existing Save Data setup which is valid, the editor will update to show the current values for you to adjust and edit. Note that if you edit the class outside of the tool and then open the editor tool, you may find some values will not read correctly.

Creating a save file with the tool

To create a save data class you’ll need to setup for variables for the class to contain. To start you’ll need to press the add field button to add your first variable.

Creating a variable

Once you have added a field, you be presented with a grouping of fields to edit for this variable like what you can see on the left here. There are 4 options that the field will show by default, but this varies on the setup. Each grouping will always have:

  • Variable Name – Which is what the variable will be called.
  • Data Type – Which is the data type the variable is defined as.
  • Collection Type – Which defines whether this variable is a collection like a list, array, queue, stack or if it is a normal single variable.

Other Options

If the data type is a class value then an extra field will appear for the class name, which is where you’d but the name of the class you want the variable to be of. This field is CaSe SeNiStIvE!

If you have the grouping with no collection type then a field will be available for a default value. This can be left blank or have a value that is valid for the type. The field will adjust based on the data type you have selected.

⚠️ Note: Sprites & Classes can’t have a default value.

You can keep adding more variables with the + Add Field button or the green + button next to each grouping and remove a grouping with the red – button.

Generating the class for use

Once you have filled in the variables you want to save, you can press the Generate New SaveData Class button to make the class with the inputs you gave. At this point the editor will refresh with the class will be placed in the following directory in your project, please delete the SaveData.cs class provided in asset package if you haven’t already at this point as it is no longer needed:

Assets/Scripts/Save/SaveData.cs

General

What setups are valid?

Save Variants

If your making your save data class yourself or editing the code generated after using the tool there are some important steps to follow to keep the save data valid. You’ll note that when you save any Vectors, Colors, Quaternions & Sprites that their datatype has the prefix of Save before it. This is out custom struct for saving these types of data. Previously you would’ve had to use these types in your code, however since 1.1.0 you can now just use the normal version and use the implicit operator to convert them to and from the save variants. So if you are writing your own class for the save manager to use you will need to use the save variants for these types which are listed below for reference:

  • SaveVector2
  • SaveVector3
  • SaveVector4
  • SaveColor
  • SaveQuaternion
  • SaveSprite

Exposure & Default Values

Every field you add must be public for the tool to work correctly, you’ll want this too as there isn’t much point of having private values in a save file. The only other issue you’ll find is with default values. By default we only support default values when defining values as a single variable and not a collection (list, array etc.). We also don’t support default values for sprites and classes. This is mostly due to the amount of backend work that would be need to make it work and the lack of instances where you’d want to use it. If you want to edit the default values outside of the editor you’ll have to note that they should be written in their raw form, for example you might use Vector2.One as the default value. This won’t work with our editor, so you should write it as new Vector2(1f,1f) instead.

Extra Setup For Saving Sprites

To save sprites you need to have you sprite asset import settings setup up in a particular way. Thankfully its nice and simple, in the import settings you need to enable the read/write toggle as well as not using any compression on the sprite you plan to save. Because of the lack of compression we advice you to use Power of 2 (256×256, 512×512, 1024×1024 etc) where possible and compress the art outside of Unity to help mitigate this issue if art file size is a problem for your product.

The About Tab

The about tab provides a little more info on the asset as well as the version number, release data and some useful links for the asset. These include a button to this documentation page, a button to open the invite to our discord server and a button to our report form to report issues with the asset and any of our other products to us.

Help

F.A.Q

Please make sure you didn’t do any of the following:

  • Set a class field that was not spelt correctly
  • Have another script in the same namespace called SaveData.cs

Please make sure the ExtraSaveTypes.cs class is imported into the project.

Please make sure that you are using the namespace and have imported the project correctly.

This is up to you. You put it where you need it! We recommend that you put it in Awake/Start Methods or in a custom method that only gets called once. If you are going to put the loading code in Update we recommend you have a boolean that is used to check if the game has loaded, once run you set it to true it running more than once.

Help

Additional Support

If you need any additional support or just have some questions you may get in touch via to following methods:

You can send me an email to the following address support@carter.games this is monitored and you will get a response within 72 hours of your request, though I normally get back to you within the hour. Note I’m UK based so if its the middle of the night for us I won’t be able to get back to you until the morning.

I have a community discord server, note that this is not just for asset support so please you the Leaderboard Manager channel in the server for your request. You can access this via assigning yourself the Assets role on the server. This is monitored and you will get a response within 72 hours of your request, though I normally get back to you within the hour. Note I’m UK based so if its the middle of the night for us I won’t be able to get back to you until the morning. The server invite link is below should you wish to use this method:

Join the Carter Games Discord Server!

Should you find an issue with our asset, the best way to let me know is via the report form on our website. you can access this via the link below:

Carter Games: Report an Bug/Issue in our products

Should you want to, you can send a message via my website contact form which we will get and response within 72 hours of your request, though I normally get back to you within the hour. Note I’m UK based so if its the middle of the night for us I won’t be able to get back to you until the morning. You can access this via the link below:

Carter Games: Contact Me

Scripting

Namespace

All code for this asset is under the following namespace(s):

// General Code
CarterGames.Assets.SaveManager

To access code from the asset you will need to be using the asset namespace in your script or use the full path of the asset script in order to access it.

Scripting

Classes

All methods in class are static and can be accessed by using class name before the method without needing a reference to an instance of the script.

// Example of usage... replacing "MyMethodHere" with the method you want to call.
SaveManager.MyMethodHere
Save Manager

Methods

SaveGame()

Saves the data provided into the method into the save file.

Example Usage

SaveManager.SaveGame(SaveData data); 
LoadGame()

Loads the game data from the file or returns a warning if not data was found.

Returns
SaveData – SaveData containing and save data that was in the save file.

Example Usage

var data = SaveManager.LoadGame();
HasSaveFile()

Checks to see if a save file exists and returns it for use.

Example Usage

if (SaveManager.HasSaveFile())
ResetSaveFile()

Resets the save file to the default values.

Example Usage

SaveManager.ResetSaveFile();
DeleteSaveFile()

Deletes the current save file.

Example Usage

SaveManager.DeleteSaveFile();
Scripting

Example

Saving and loading your game is somewhat subjective as each game requires a different setup. However, most games will want to load their data on the start of the game, edit it when levels are complete and save it when progress is made. We recommend having a static or persistent object that holds a copy of the save data class as a variable which can be edited on the fly and using in the saving and loading process. Below are some examples of how to go about each stage. These can also be seen in the example script in the asset which is used in the example scene of the asset.

Loading

Here we’re assuming that you have an empty GameObject or similar which holds this script to load the game when the scene starts. This is one of the better ways of loading the game if you need the data in each scene.

// Gets the game save from the file....
SaveData loadData = SaveManager.LoadGame();

// Applies the values to the 
player.name = loadData.playerName;
player.health = loadData.playerHealth.ToString();
player.trandform.position = loadData.playerPosition.ToString();
player.sprite = loadData.playerSprite;

Saving

Saving can be done whenever, however it is recommended that you only save when necessary to avoid an impact to your games performance.

// Makes a new save data class instance for use...
SaveData saveData = new SaveData();

// Applies the values to the class for saving...
saveData.playerName = player.name;
saveData.playerHealth = player.health;
saveData.playerPosition = player.transform.position;
saveData.playerSprite = player.sprite;

// Saves the game with the class creates/edited above...
SaveManager.SaveGame(saveData);

Change Log

Minor Update

1.1.0

Added improvements to the editor tool for the asset as well as a facelift for the asset on the store.

🏪 Store Listing

  • Updated asset artwork to a new gradient style.
  • Updated key images to be up to date with the latest version of the asset.
  • Updated the store description with the latest changes to the asset.

🎨 Asset Changes

  • Improved save data editor tool.
  • Move editor tool to Tool/SaveManager | CG.
  • Added additional options to the navagation tab to allow the user to reset the save data.
  • Added support for default values for some save data types.
  • Added options to save Quaternions, Sprites, Queue’s, Stack’s, Doubles & Bytes.
  • Added implicit operators to allow save variants to be converted to their normal types with no extra work on the end user.
  • Updated documentation for latest version
Minor Update

1.0.2

Updates and general improvements to the existing codebase.

🏪 Store Listing

  • Updated the asset title to remove the “(CG)” characters after the asset name. This has been replaced with “| CG” instead to

    look a little neater.
  • Updated the main asset description to explain more about the asset and its features.
  • Updated all links to be correct for the asset.
  • Updated to key images to all be the same size as the main key image.
  • Updated the asset colour scheme to be more pastel, the old colour was a bit abrupt.

🎨 Asset Changes

  • Updated the Save Manager Logo on the asset editor window.
  • Updated the priority of the Save Manager in the Carter Games navigation tab menu.
  • Corrected the spacing for Save Data Editor in the navigation tab menu.
  • Updated commenting on all code.
  • Updated the example in the asset so that the user can refer back to it without needing the savedata class to be set in a

    particular way.
  • Name spaced all example code into CarterGames.Assets.SaveManager.Example so that the user does not accidently use

    example code instead of the asset itself.
  • Added a new method to reset the save file when called.
  • Cleared the savedata class so it is ready for the user to add their own stuff right away.
Patch

1.0.1

Fixed to the discord server link and graphics on the store page.

🏪 Store Listing

  • Fixed the store page discord logo to be a proper logo to comply with the store requirements.

🎨 Asset Changes

  • Updated the discord invite, as it was broken, to be our redirect so it doesn’t need updating again.
Original Release

1.0.0 | Initial Release

Initial release of asset, first public version.

2.x.x is coming soon, documentation etc for it will appear here when it is ready.