How To: Save Only Character Data
Posted: Wed May 27, 2020 10:49 am
This post explains how to use the Save System to save only character data (Opsive UCC in this example) and not the current scene or data about other objects.
To save only the Opsive player state and position:
1. Set up a Save System GameObject with these components: SaveSystem, JsonDataSerializer, and PlayerPrefsSavedGameDataStorer.
3. Add a UCCSaver component to the player. Tick the options you want to save. Do not add any other saver components to any other GameObjects unless you want the Save System to save their info, too.
4. To save the player's data to a string:
You can then store this string however you want.
5. To restore the player's data:
To save only the Opsive player state and position:
1. Set up a Save System GameObject with these components: SaveSystem, JsonDataSerializer, and PlayerPrefsSavedGameDataStorer.
- Options: You can use BinaryDataSerializer or your own DataSerializer subclass instead of JsonDataSerializer, and DiskSavedGameDataStorer or your own SavedGameDataStorer subclass instead of PlayerPrefsSavedGameDataStorer. The saved game data storer won't be used; it just silences a warning from the Save System about not having a SavedGameDataStorer.
3. Add a UCCSaver component to the player. Tick the options you want to save. Do not add any other saver components to any other GameObjects unless you want the Save System to save their info, too.
4. To save the player's data to a string:
Code: Select all
using PixelCrushers;
...
string s = SaveSystem.Serialize(SaveSystem.RecordSavedGameData());
5. To restore the player's data:
Code: Select all
SaveSystem.ApplySavedGameData(SaveSystem.Deserialize<SavedGameData>(s));