{"id":13662946,"url":"https://github.com/IntoTheDev/Save-System-for-Unity","last_synced_at":"2025-04-25T13:30:54.360Z","repository":{"id":37437004,"uuid":"207866083","full_name":"IntoTheDev/Save-System-for-Unity","owner":"IntoTheDev","description":"Save System for Unity with AOT (IL2CPP) and assets references support.","archived":false,"fork":false,"pushed_at":"2024-06-24T14:01:19.000Z","size":519,"stargazers_count":229,"open_issues_count":1,"forks_count":18,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-05T06:33:46.455Z","etag":null,"topics":["filesystem","game-development","save","save-and-load","savegame","unity","unity-asset","unity-scripts","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IntoTheDev.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-11T17:14:00.000Z","updated_at":"2024-10-29T10:42:50.000Z","dependencies_parsed_at":"2024-05-04T16:31:02.047Z","dependency_job_id":"67473e0f-0f25-4b49-b324-48d87e6dbf1f","html_url":"https://github.com/IntoTheDev/Save-System-for-Unity","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSave-System-for-Unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSave-System-for-Unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSave-System-for-Unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSave-System-for-Unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IntoTheDev","download_url":"https://codeload.github.com/IntoTheDev/Save-System-for-Unity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224003726,"owners_count":17239495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","game-development","save","save-and-load","savegame","unity","unity-asset","unity-scripts","unity3d"],"created_at":"2024-08-02T05:02:12.903Z","updated_at":"2024-11-10T19:30:44.591Z","avatar_url":"https://github.com/IntoTheDev.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# Save System for Unity\n\n### TODO\n- [x] Assets References\n- [x] AOT support\n- [x] Upload MessagePack version to separate branch? MessagePack version has better performance and less file size (WIP)\n\n\n## Features\n- Can save pretty much everything (Vector, Quaternion, Array, List, Class, Struct, etc)\n- Can save assets references\n- As easy to use as PlayerPrefs\n- Fast in terms of performance. Even simple int saving way more faster than ```PlayerPrefs.SetInt()```. Performance test at the end of README\n- Save files are encrypted\n- Multiple profiles\n\n## How to Install\n\n### Git Installation (Best way to get latest version)\n\nIf you have Git on your computer, you can open Package Manager indside Unity, select \"Add package from Git url...\", and paste link ```https://github.com/IntoTheDev/Save-System-for-Unity.git```\n\nor\n\nOpen the manifest.json file of your Unity project.\nAdd ```\"com.intothedev.savesystem\": \"https://github.com/IntoTheDev/Save-System-for-Unity.git\"```\n\n### Manual Installation (Version can be outdated)\nDownload latest package from the Release section.\nImport SaveSystem.unitypackage to your Unity Project\n\n## Usage\n\n### Saving\n\n```csharp\nfloat health = 100f;\nDataSerializer.Save(\"SaveKeyHere\", health);\n```\n\n### Loading\n\n```csharp\nfloat health = DataSerializer.Load\u003cfloat\u003e(\"SaveKeyHere\");\n```\n\n### Check for key\n\n```csharp\nif (DataSerializer.HasKey(\"SaveKeyHere\"))\n\tfloat health = DataSerializer.Load\u003cfloat\u003e(\"SaveKeyHere\");\n\t\n// OR\n\nfloat health;\n\nif (DataSerializer.TryLoad(\"SaveKeyHere\", out float value))\n\thealth = value;\n```\n\n### Delete key\n\n```csharp\nDataSerializer.DeleteKey(\"SaveKeyHere\");\n```\n\n### Delete all save file data\n\n```csharp\nDataSerializer.DeleteAll();\n```\n\n### Change profile. Old profile will be saved and new one is loaded.\n\n```csharp\nDataSerializer.ChangeProfile(profileIndex: 1);\n```\n\n### Complex example\n\n```csharp\nusing System.Collections.Generic;\nusing ToolBox.Serialization;\nusing UnityEngine;\n\npublic class Player : MonoBehaviour\n{\n\t[SerializeField] private float _health = 0f;\n\t[SerializeField] private List\u003cItem\u003e _inventory = new List\u003cItem\u003e();\n\n\tprivate const string SAVE_KEY = \"PlayerSaveData\";\n\n\tprivate void Awake()\n\t{\n\t\tDataSerializer.FileSaving += FileSaving;\n\n\t\tif (DataSerializer.TryLoad\u003cSaveData\u003e(SAVE_KEY, out var loadedData))\n\t\t{\n\t\t\t_health = loadedData.Health;\n\t\t\ttransform.position = loadedData.Position;\n\t\t\t_inventory = loadedData.Inventory;\n\t\t}\n\t}\n\n\t// This method will be called before application quits\n\tprivate void FileSaving()\n\t{\n\t\tDataSerializer.Save(SAVE_KEY, new SaveData(_health, transform.position, _inventory));\n\t}\n}\n\n// If you want to make scriptable object or any other asset saveable then you need to add that asset to Assets Container. \n// See guide below\n[CreateAssetMenu]\npublic class Item : ScriptableObject\n{\n\t[SerializeField] private string _name = string.Empty;\n\t[SerializeField] private int _cost = 100;\n}\n\npublic struct SaveData\n{\n    [SerializeField] private float _health;\n    [SerializeField] private Vector3 _position;\n    [SerializeField] private List\u003cItem\u003e _inventory;\n\n    public float Health =\u003e _health;\n    public Vector3 Position =\u003e _position;\n    public List\u003cItem\u003e Inventory =\u003e _inventory;\n    \n    public SaveData(float health, Vector3 position, List\u003cItem\u003e inventory)\n    {\n        _health = health;\n        _position = position;\n        _inventory = inventory;\n    }\n}\n```\n\n### How to make asset saveable\n\n1. Open ```Assets Container``` window. Window/Assets Container. Window looks like this:\n\n![image](https://user-images.githubusercontent.com/53948684/117006513-f7dd9a80-ad01-11eb-8c14-bd665a88dfe2.png)\n\n2. Select path where your assets stored. If you already have path field then press the ```Select Path``` button or ```Add Path``` if not. In my case path is ```Assets/ScriptableObjects/Items```.\n\n3. Press the ```Load assets at paths``` button.\n\n4. Repeat step 3 every time you create a new asset.\n\n![image](https://github.com/IntoTheDev/Save-System-for-Unity/assets/53948684/10e575a2-a4f6-4693-98c3-1e04dca618ec)\n\n### AOT platforms\n\nAOT (IL2CPP) works without any additional work, but IF some types do NOT serialize, please follow the steps below.\n\nYou need to create a simple C# class that implements the ```ITypeProvider``` interface. Then, you need to define the types that fail to save for some reason.\n\nAlthough it should work without an ITypeProvider, for the sake of simplicity, I'll use the case above as an example.\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing ToolBox.Serialization;\nusing UnityEngine;\n\npublic sealed class TestProvider : ITypeProvider\n{\n    public Type[] GetTypes()\n    {\n        return new Type[]\n        {\n            typeof(SaveData),\n            typeof(Vector3),\n            typeof(List\u003cItem\u003e)\n        };\n    }\n}\n\n```\n\n## Performance test\n\n### PlayerPrefs result: 329 milliseconds\n### Code:\n\n```csharp\nusing Sirenix.OdinInspector;\nusing System.Diagnostics;\nusing UnityEngine;\n\npublic class Tester : MonoBehaviour\n{\n\t[SerializeField] private int _number = 0;\n\n\t[Button]\n\tprivate void Test()\n\t{\n\t\tStopwatch stopwatch = new Stopwatch();\n\t\tstopwatch.Start();\n\n\t\tfor (int i = 0; i \u003c 10000; i++)\n\t\t{\n\t\t\tPlayerPrefs.SetInt(\"SAVE\", _number);\n\t\t\t_number = PlayerPrefs.GetInt(\"SAVE\");\n\t\t}\n\n\t\tstopwatch.Stop();\n\t\tprint(stopwatch.Elapsed.TotalMilliseconds);\n\t}\n}\n\n```\n\n### DataSerializer result: 18 milliseconds\n### Code:\n\n```csharp\nusing Sirenix.OdinInspector;\nusing System.Diagnostics;\nusing ToolBox.Serialization;\nusing UnityEngine;\n\npublic class Tester : MonoBehaviour\n{\n\t[SerializeField] private int _number = 0;\n\n\t[Button]\n\tprivate void Test()\n\t{\n\t\tStopwatch stopwatch = new Stopwatch();\n\t\tstopwatch.Start();\n\n\t\tfor (int i = 0; i \u003c 10000; i++)\n\t\t{\n\t\t\tDataSerializer.Save(\"SAVE\", _number);\n\t\t\t_number = DataSerializer.Load\u003cint\u003e(\"SAVE\");\n\t\t}\n\n\t\tstopwatch.Stop();\n\t\tprint(stopwatch.Elapsed.TotalMilliseconds);\n\t}\n}\n```\n\n## License\n[DataSerializer](https://github.com/IntoTheDev/Save-System-for-Unity/tree/master/DataSerializer) folder is licensed under the MIT License, see [LICENSE](https://github.com/IntoTheDev/Save-System-for-Unity/blob/master/DataSerializer/LICENSE) for more information.\n\n[OdinSerializer](https://github.com/IntoTheDev/Save-System-for-Unity/tree/master/OdinSerializer) folder is licensed under the Apache-2.0 License, see [LICENSE](https://github.com/IntoTheDev/Save-System-for-Unity/blob/master/OdinSerializer/LICENSE) for more information. Odin Serializer belongs to [Team Sirenix](https://github.com/TeamSirenix)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIntoTheDev%2FSave-System-for-Unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIntoTheDev%2FSave-System-for-Unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIntoTheDev%2FSave-System-for-Unity/lists"}