-
Notifications
You must be signed in to change notification settings - Fork 3
Getting Started
There are two components that handle saving and loading, respectively: the GameSaver and GameLoader. One of each should be in every scene, and you can easily do so by putting the SaversAndLoaders prefab in said scenes. GameSavers create save data on demand, which can then be written to or read from the disk. Or loaded, which is the GameLoader's job.
The save data is represented by the GameSaveData class, which is meant to keep track of all the state you want loaded (that Unity itself doesn't handle). By default, the system only has it contain the state of Fungus's built-in Flowcharts and (if you import the provided optional scripts) the Slot-based Narrative Log System (SBNLS) right here.
Note that if you're using a later version of Fungus (3.13 or later), you'd best not import the SBNLS linked above; that will cause errors.
The system's made to be extensible, so you can have other types saved and loaded in your game.
You put copies of the SaveMenu and SaversAndLoaders prefabs into the scenes where you want the save menus to be available. You'll then want to use Flowcharts to have it interact with the UI. For example, saving to a certain slot when the Save button is clicked or deleting from a slot when the Delete button is clicked. There's an example of this you can check out in the NewSaveSystemSandbox scene.
As the name implies, this contains the UI of the save menu. If you want to have your own custom one (I'll admit, the default's not much of a looker), then you'd best make a copy of it, edit that copy, and use that instead of the default.
As for how it works in a nutshell... There are three core components that every version of this prefab should have:
- SaveMenu: Main interface for the save system overall
- SaveSlot: Displays things about the save data they're linked to, and they are what you click to decide what save file to load from or save to.
-
SaveSlotManager: Manages the SaveSlots in response to actions done related to the saving and loading.
The SaveSlotManager does its thing mainly by responding to actions related to saving and loading.
Other than it being slot-based (just have at least one object set to hold the slots), you can set up your save UI any way you like. Just make sure you have the components in place with the right fields set in the Inspector. I suggest using the SaveMenu prefab as a base and working from there.
This by default contains the scripts needed to handle various parts of the saving and loading processes. If there's something you want saved that this system doesn't support out of the box, you can code your own saver and loader scripts, adding them to this prefab. See the "How do I extend this for other types?" section for more info on that.
First, subclass these classes.
-
SaveData: Contains the state to save.
-
DataSaver: Creates instances of your SaveData subclass, encapsulates each into a SaveDataItem, and returns a list of said items for the GameLoader to work with.
-
SaveLoader: Takes an instance of your SaveData subclass (or a SaveDataItem encapsulating it) and loads state from it appropriately.
You might want to change the loadPriority field in your custom SaveLoader in case you need its data type to be loaded sooner or later than others.
Lastly, test your new classes and make sure they work.
Where you press Continue on the title screen and the one save slot is loaded? Sure you can! Just don't let the user access the save menu UI, making sure to use the SaveManager to create and load saves as appropriate.
I hope these flowcharts help:
- Saving process: https://docs.google.com/drawings/d/1hP4OlqFDEISaYuaMnEIgkancQZ4qYyjj5y4x6d47mKA/edit?usp=sharing
- Loading on startup: https://docs.google.com/drawings/d/1-XGeUm6tf-4T17IeFhBaA0ShrhyE09YxqYCBAjz9rBA/edit?usp=sharing
- Loading on demand: https://docs.google.com/drawings/d/1FgPHBJW-oFwqj1B3IcN48Uh3A0CbtlK-QvtS2XrP8R4/edit?usp=sharing
- Deleting saves: https://docs.google.com/drawings/d/1g1Va4Nq_UlAYUNIivbJLpNH9wvKpHg-sFdeQqK84ArI/edit?usp=sharing
There's the API docs on this wiki. You can also create an Issue thread on the repo asking for help. You can also email me at the address I mentioned on the repo's main page. Constructive feedback is also welcome.