Using Auto Save
In this guide, we'll be using the Auto Save feature to save and load scene objects including their components and children in specific examples.
The Auto Save feature lets you to save and load data without having to write code, while it provides a decent API to save, load and delete the data which lets you to combine it with your more advanced use cases.
You can also use the Auto Save component without Auto Save Manager, which allows you to control the serialization of a certain GameObject children and components.
Getting Started
First, make sure Auto Save Manager is present in the scene, a quick workflow is to right-click on the hierarchy and use Bayat > Save System > Save System Manager menu to create all the necessary components:
Then, add Auto Save component to any object that you want to save:
Now, if you want also save the children of this particular object, then enable the Serialize Children, then if you want to ignore some specific children, add them to the Excluded Children list, but if you want to serialize a specific set of its children, then enable both Serialize Children and Serialize Excluded Children and add those children to the Excluded Children list, you can use the Auto Save Manager menu to simplify the process:
Then, if you want to save the components of this object, enable Serialize Components to serialize all components of the objects, then if you want to ignore some components, add them to the Excluded Components list, but if you want to just serialize a specific set of components, add them to the Excluded Components and then enable Serialize Excluded Components to only serialize those components.
Note
In a nutshell, the Serialize Excluded Children and Serialize Excluded Components options invert the behavior of the lists, for example, if you want to ignore some children or components to be ignored during serialization of this game object then you can disable the Serialize Excluded options and add those children or components to their corresponding list, otherwise, you can enable those options and add any object to the lists, then only those objects which inside the list will be saved.
Once you have setup the scene and added the Auto Save component to the objects that you want to save, you can save the data using one of the below ways.
Saving Automatically using Events
By default, the Auto Save Manager uses a predefined set of events to save and load the data, so you can just run the game and see it works in the runtime, and you can simply switch between the events and find the most reliable one based on your requirements.
Learn more about these events >
Saving Manually using API
You can also use the API directly to save and load the data even by usingthe predefined events, by incorporating this, you can save the data after each modification or any siginificant game change:
public class ManualAutoSave : MonoBehaviour {
public AutoSaveManager autoSaveManager;
void Start() {
autoSaveManager.Save();
}
void OnApplicaitonPause() {
autoSaveManager.Load();
}
}