Creating Save Slots
With Easy Save you can create save slots with a single-click which can be customised for your purposes. This requires Unity 2020.3 or newer, and Text Mesh Pro and Unity UI packages installed from Window > Package Manager.
Adding save slots to your scene
To add save slots to your scene, go to Assets > Easy Save 3 and select Add Save Slots to Scene or Add Load Slots to Scene.
Add Save Slots to Scene will add a UI which has a ‘Create new slot’ button and shows a confirmation dialog if the slot being selected already exists. Add Load Slots to Scene does not have a ‘Create new slot’ button and won’t perform an overwrite check.
Now if you’re not specifying your own filename/settings, you don’t need to do anything else. Easy Save will automatically use the selected save slot when using Auto Save or calling Easy Save’s methods.
How save slots work
When a user selects one of the save slots, the default save file is set to the name of the save slot. This means that when you call Easy Save’s methods or use Auto Save, it will use this filename as long as you have not specified your own filename.
For example the following code will work with save slots because we’ve not specified our own filename:
1 |
ES3.Load<Type>("key"); |
But this code would not work with save slots because we’ve specified our own filename:
1 |
ES3.Load<Type>("key", "MyCustomFile.es3"); |
You can get the currently selected save slot using the static ES3SlotManager.selectedSlotPath variable. This will be a path relative to Application.persistentDataPath, or null/empty if no slot is selected.
When the user creates a save slot, Easy Save won’t automatically create the file for this slot unless you enable the Auto Create Slot Button option. By default it is your responsibility to save data in order to create the file after the user creates the save slot.
When the user deletes a save slot, it’s save file is not deleted immediately. Instead it is marked to be deleted and will be deleted when the slots dialog is closed, made inactive, or destroyed (i.e. because the scene has changed or the application has quit).
When the user presses the Undo button the save slot will be unmarked for deletion.
Changing settings
The settings for the save slots can be found in the ES3SlotManager Component attached to the Easy Save Slots GameObject (this can be found beneath the Easy Save Slots Canvas GameObject).
It provides the following settings:
- Show Confirmation If Exists
Shows a confirmation dialog if save data already exists for the slot the user has selected. - Show Create Slot Button
Whether to display the button used to create a new save slot. - Auto Create Save File
Whether we should automatically create an empty save file when the user creates a new save slot. This will be created using the default settings, so you should set this to false if you are using ES3Settings objects. - Select Slot After Creation
Whether a slot should be selected after a user creates it. - Load Scene After Selected
The name of a scene to be loaded after the user selects a save slot. The scene must have been added to the ‘Scenes in Build’ list of your Build Settings. - On After Select Slot
A method to be called after the slot is selected. - On After Create Slot
A method to be called after the slot is created by the user, but not selected. - Slot Directory
The directory in which save files should be stored. This will be relative to Application.persistentDataPath and should have a leading ‘/’. - Slot Extension
The file extension to be used for save files.
Any settings not listed here should not be changed unless you are changing the structure of the save slots.
Customising the save slots
In most cases you should only need to customise how the user interface looks. This can be done by following Unity’s guides and tutorials on UGUI.
If you wish to modify the structure of the save slots, we strongly recommend understanding how each of the scripts in Assets/Plugins/Easy Save 3/Scripts/Save Slots/ work. These are fully commented, but here is an overview of each script:
- ES3SlotManager.cs
Responsible for settings, and for creating the save slots. - ES3Slot.cs
Attached to the template for the save slots. This handles slot selection, deletion, undoing deletion, and overwriting. - ES3CreateSlot.cs
Attached to the Create New Slot button. This handles creation of new slots and prevents users from creating a slot which already exists. - ES3SlotDialog.cs
Attached to all dialog boxes. This provides the other scripts with the ability to respond to Confirm button being pressed, and closes the dialog when the Cancel button is pressed.
The Easy Save Slots Canvas prefab can be found in Assets/Plugins/Easy Save 3/Scripts/Save Slots/. If you wish to modify this we recommend making a copy rather than modifying the original prefab.
If you wish to change how the scripts work you should create your own class which inherits from the script and override the methods you wish to change rather than modifying the scripts themselves.
For example if you wanted to destroy the Save Slots window rather than making it inactive when the user presses the Close button, you could replace the ES3SlotManager script with the following:
1 2 3 4 5 6 7 |
public class CustomSlotManager : ES3SlotManager { public override void Close() { Destroy(transform.parent); } } |