Saving Custom Data: Simple Method
Last updated
Last updated
For most scenarios, the simple method is more than enough to successfully save custom data. Except specific cases from data that needs to be saved from the Inventory Pro Add-On, the rest of the data in the Save & Load Add-On is Saved by implementing this method.
Simple & Fast to Implement
Only supports Serializable Data Types ( int, floats, bools, etc... )
Attribute Based [SaveField]
No-Code Required
Imagine you’ve created a custom script that holds custom data that needs to be saved. For this example, let’s say you have a counter that increments an int
every 5 seconds, and you want to store the value of that int
whenever the game is saved.
IMPORTANT: The must exist in the scene for data to be saved.
You don’t need to manually add the DataPersistenceManager
to each scene, as it is marked with [DontDestroyOnLoad]
. Simply place the DataPersistenceManager
in your Main Menu scene. When starting the game from a gameplay scene, data won’t be saved. However, when starting from the Main Menu, the DataPersistenceManager
will persist across different scenes, ensuring data can be saved.
Below, you can take a look at the example code:
Now, we need to tell the Save & Load system which variable we want to save.
Your custom script has data that can be serialized and saved.
Your custom script implements cowsins.SaveLoad library.
Your custom script inherits from Identifiable.
You update the value to be saved and notify GameDataManager through StoreData() method.
Once you are done Saving & Loading data, you can run custom behaviour based on the loaded data. Whenever LoadFields is called, LoadedState() will also be called.
Just like that, value will be serialized as a into the data.json file.
You can access this value from the , at the Custom Objects Dropdown.
Check for more Information.