Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Save Game Free - Complete Free Save Game Solution

Discussion in 'Assets and Asset Store' started by hasanbayat, Feb 22, 2017.

  1. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Easiest Way to Save your game for Free!

    Save your player data and load it easily at lightning speed and securely.

    Built-in Serializers:
    • JSON Serializer (Recommended)
    • Binary Serializer
    • XML Serializer (Added in Update 1.5.6)
    Features:
    • Cross Platform Support (PC, Mac, Linux, Android, iOS, Windows Phone, Tizen)
    • Easy to Use
    • Free to Use
    • Simple but Powerful
    • Code Comments
    • Built-in JSON and Binary Serializer with encryption for security
    Get it from here:
    https://www.assetstore.unity3d.com/#!/content/81519

    If you have any issues say it here or file it at https://github.com/BayatGames/SaveGameFree/issues
    Any contributor is welcome.
    https://github.com/BayatGames/SaveGameFree

    Patreon

    If you like it Write a Review for it or post a reply here.

    Support and News
     
    Last edited: Nov 28, 2017
    DerrickMoore, Mauri and theANMATOR2b like this.
  2. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
  3. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi Ruchir.
    Currently Save Game Free does not supports any other unserializable types like Unity Types.
    You have two choices:
    1. You can create a custom type from unity types and make them serializable. like Vector3 you can replace it your own MyVector3 class and make it serializable.
    2. You can wait for Save Game Pro get released on Unity Asset Store. it can save and serialize everything you need. Visit our development board
    Also i'm going to add more supported types to Serializer Free, it currently only supports Serializable types.

    Thanks.
    Kind Regards.
     
  4. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
  5. TeohRIK

    TeohRIK

    Joined:
    Jan 22, 2014
    Posts:
    106
    Hi, if let say I already call the initialize at main menu scene, do I need to initialize again after I switch to gameplay scene?
     
  6. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi.

    No, there is no need to reinitialize the Save Game Free after scene loading, because Save Game Free uses static properties and methods to save it's state in the game and it is not relates to the scene loading.
    Be easy, just call Saver.Initialize(); once as you need as where you want. :)

    Thanks.
     
  7. TeohRIK

    TeohRIK

    Joined:
    Jan 22, 2014
    Posts:
    106
    Ok, thanks!
     
  8. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    426
    Sorry for the newbie, possibly naive question... what are the differences/advantages of using this over PlayerPrefs?

    Cloud Save is an obvious difference, but doesn't that add with it additional problems, like requiring a network connection and syncing current save state across different devices... Does the asset handle all that?
     
  9. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi.

    This is good question.

    By using Save Game Free you will be able to save your game data in different formats (Binary, JSON, XML) with encryption, so no one will be able to modify saved values, also save game free can save complex classes that marked as serializable, also in the Gold Update you will be able to save Vector3, Quaternion, Mesh, ...

    Also in the Gold Update you can save your game data to your web server or cloud server.

    The Save Game Free just saves the data you need in the Web Server and all you need is to do naming identifiers to be able to sync data across platforms. (it is easy to implement by using Save Game Free)

    This asset only handles it's own part, "Saving data".

    PlayerPrefs just saves some simple data types that they can be easily cheated, but if you are looking for a cross-platform, secure and web save system, this is good choice.

    Let me know if you have any further questions.

    Thanks.
     
    andreiagmu likes this.
  10. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    426
    Thanks for the super fast and informative reply. Definitely a sign of a good asset :)
     
    hasanbayat likes this.
  11. vorora

    vorora

    Joined:
    Mar 17, 2015
    Posts:
    34
    Hello. I have a few questions after trying the asset. (I only used PlayerPref for my old games, so this is quite new to me.)

    - By default API 'SaveGame.Save<Type> ( "xxx", xxx);', it will save as Binary format, correct?
    - If I want to save as other formats, I have to drag prefab 'Serializer Dropdown' to the scene and select the format I want, right?
     
  12. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi.

    No, The default format is JSON.

    No, You can change the format using SaveGame.Serializer = new SaveGameBinarySerializer ();, you can use serializers that exists in BayatGames.SaveGameFree.Serializers namespace.

    Any further questions are welcome.

    Please use my email address for faster response: hasanbayat1393@gmail.com

    Thanks
     
    vorora likes this.
  13. vorora

    vorora

    Joined:
    Mar 17, 2015
    Posts:
    34
    Thank you very much.
     
  14. gm0124816

    gm0124816

    Joined:
    Sep 12, 2017
    Posts:
    10
    Nice and easy ! It is almost like a good old fashioned INI file (but possibly encrypted :) )

    Just one question : "Can I choose my filename (and location) in the free version or is that something for the pro version ?"

    A tip if You need to delete the files for testing (like a 'clean install') in editor mode, here is the location:

    Debug.Log("Data location : " + Application.persistentDataPath);
     
    blazingPotato likes this.
  15. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Yes, you can choose the full path.

    Just use SaveGame.Save (identifier); then pass your file path and name instead of the identifier.

    It is a feature in both free and pro versions.

    I would be happy to hear your opinions and ideas.

    Also for clearing data in edit mode, I am going to create an Editor Window for Save Game Free that allows managing saved data in edit mode, for example, you can clear all saved data, open the saved path in the file browser, ...

    Thanks.
     
  16. gm0124816

    gm0124816

    Joined:
    Sep 12, 2017
    Posts:
    10
    Thanks for the fast and useful reply !

    The suggested features for clearing data look promising, but you should integrate these only for the Pro version. In the free version, people should do that themselves, after all it is a free version, but they should know where to look. To be honest, your Pro version is reasonably priced, so that should not be the problem ...

    I do miss one crucial feature and that is the possibility to create (encrypted) files/items from within the editor. Let me explain what I mean. If I use encryption to store the data, I cannot create a simple txt-like file somewhere in my project having the initial values in it. Now, I need to create a script, saving this specific data via code in that script, running it once so that I have the data in the encrypted file and then delete or disable the script. That is fine for custom types, but it should be possible to do that from withing a form in the editor for basic types like booleans, integers, strings, vector2/3d, etc and collections/lists/sets. That way I can configure the initial state of the game or create lists I do not want in code from within the editor without having to write this code, I could potentially forget to disable the script and end up in production code with this ...

    Another solution for this is that you would allow us to provide a txt file with a non encrypted content and that, via a form in the editor, it could be encrypted and saved somewhere else in the project (eg a Resources folder). Of course you would have to provide us with the right structure per type/file for the txt file to have it correctly encrypted. This might be an easier solution.

    If you would create such a feature (of course only for the Pro version), I would strongly consider buying your Pro asset and use it a lot in production code ! Like I said before I'm looking for an encrypted (ini) file solution (I already have a database solution) and I prefer not to write one myself. Yours looks to be a perfect match.
     
  17. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Looks a good idea.

    So you mean creating initial data for editor right inside the Unity Editor or creating initial data for the whole game inside the Editor?

    Thanks.
     
  18. gm0124816

    gm0124816

    Joined:
    Sep 12, 2017
    Posts:
    10
    I mean (initial) data for the game itself. For instance a Hash List could hold the order of the levels to be loaded during the game. We need to create that list somewhere before it gets encrypted (and before the game is started for the first time (or the second, third etc time) - both in the editor and in the 'real game' - otherwise the game will not work).

    Data is best kept out of the code as code should handle data, but not embed it. If I would change the order of my levels in the above example I only need to update that single file of yours and not the complete game and best of all, I do not need to make a 'new version' (compiling, creating the distributables, etc) of the game. Modify and distribute one (small) file and one (small) file only. If I wanna do it 'right' I keep a second file (key value pair like a dictionary) where I keep for every 'changeable file' the name as the key and the version of the file as the value. In that case I need to update only two small files. Should be perfect doable with a files of yours ! A workflow like that is just good practice and takes one on a productive and safe path.

    The editor would be the perfect place to create it in a location (folder) of our choosing (probably a Resources folder somewhere in the project). Maybe the way one creates a C# script or UI component in the editor is a good way to look at it. In some folder (of our choosing) one right clicks and in the popup menu (with possible sub menus for the divers types) you click what is needed and the file is created. If we click on the file, in the inspector we can modify and save the automatically decrypted (and readable) data into the encrypted file again.

    Later, in the code (via your methods and functions), we can retrieve, add or modify this data during game play.

    Since you support encryption it might be good to have one global 'Save Game Manager' or 'Bayat Games Manager' where the common stuff is kept like a key, seed or whatever you need for the encryption. This means only one key/seed for the entire project (and for the inspector !). That way one does not have to keep keys and seeds written down somewhere else. In best case you add a dictionary for this in the manager so different departments can have different keys. Just pick the right one in the code (referring to the key values in the dictionary in the 'manager').

    It might also be a good place for you to keep a 'version' field (dropdown box) (1.0; 1.1 .. 1.17; 2.0 etc). If you modify the encryption algorithm or the code (adding or changing), you can keep your code backwards compatible. That way you can keep the same procedures and functions (as long as the signature does not change). Is the version smaller then major x and minor y use internal function 'X' otherwise use 'Y' ...

    There is no bigger misery for us users of wonderful created components than discovering a supplier changed the code and it is not backwards compatible !

    Hope this makes the matter clearer.
     
  19. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    The solution for your first paragraph is the ScriptableObject, you can add a List field to the ScriptableObject and add your levels right inside the Inspector then what you need to save is the Locked/Unlocked and Complete/Incomplete State of levels.

    The whole idea is awesome, but the implementation needs fixes because Save Game Free needs to be modular, we have a hard work to add the data editor.

    Because the user is specifying the Encryption Type, Save Location, ... also, the user can add its own custom encryption, save location, ...

    In other words, you mean to make a data editor for default values that you can retrieve them in runtime and modify by your needs and store them in the user local storage.

    But the most of these features can be implemented using ScriptableObject and we can use ScriptableObject to specify default values and data.

    Thanks for your complete explanation, excuse me if I missed your mean.

    Thanks.
     
  20. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Hi
    where i find the json save file?
     
  21. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi.

    Try this script, it outputs the save path:
    Debug.Log("Data location : " + Application.persistentDataPath);
    In windows, the path is C:\Users\%USERNAME%\AppData\LocalLow\Company Name\Game Name

    Thanks.
     
  22. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Hi

    Thanks

    what is the big difference between free and pro version?
    if a use the free and after upgrade to pro is compatible?
     
  23. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    The main difference is the Supported Types, Save Game Pro supports more Types and has more Editor Integration.
    The Pro version does not compatible with the free version, but you can make it compatible in seconds.
    Have a look at Trello Board for Features: https://trello.com/c/SgYpFsfd/35-save-game-pro
    You should choose whether to use Pro or Free at the start of the project.

    But I have planned to make them compatible, because it needs a lot of work in Unity environment, so excuse me if they aren't compatible.

    Thanks.
    Hope you enjoy Save Game Free.
     
  24. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Hi Again :)
    I want to buy the Pro Version, but I need to know if is possible create save games in different slot?
     
  25. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    What do you mean by different slots?
    You can handle slot-based games in both of them, but it is easier using Save Game Pro.
    But you can handle this in both Save Game Free and Save Game Pro. (but its worth to buy pro version, because the pro version will receive an update in this month that changes many things)
    You can do this using Save Game Free by saving all files to a specific directory and then load all data from the specified directory and the same process in Save Game Pro.

    Any further questions are welcome
    Hope this help.
    Thanks.
     
  26. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Hi
    I refer to this

    can i easily create this?
     
  27. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Yes, you can.

    Slots are same as directories, you just need to call your directories as slots.
    You just need to prepend all of the identifiers with the selected slot.
    I am going to add a slot based save example in the Save Game Pro Gold Update, you can find the development board at https://trello.com/c/SgYpFsfd/35-save-game-pro
    You can use both Save Game Free or Pro to do this.
    Just call SaveGame.Save (currentSlot + "/" + "myIdentifier", myObject); and all done.
    Then you can load them back using SaveGame.Load (currentSlot + "/" + "myIdentifier");.
    For example, you can save a score at SaveGame.Save (currentSlot + "/myScore", myScore); and then load back using same identifier.

    Hope this helps.
    Thanks.
     
  28. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Thanks. I just buyed:)
     
    hasanbayat likes this.
  29. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Hi Again

    I have a problem. I want to save a List<Class> , but get a error.
    i have to create a custom type save?
     
  30. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Yes, until Gold Update releases.

    Currently, you have to create a custom type.

    Thanks.
     
  31. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    ok, when you think release the Gold Update?
    thanks
     
  32. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    I said everyone in this month and this month is getting the end, that means this will be released in these days, 5-10 days later, or maybe sooner!

    I would be happy to hear your ideas and opinions.

    Thanks.
     
  33. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    251
    Save Game Pro is a very good asset and easy to use, but i think need a better documentation. This is to basic and don't explain how work the Editor Integration? Game Save Scrip (is even't mentionend).
    I think need create tutorials (youtube). not all people are expert.
    if you look the store. the asset wih more selled is Playmaker.

    you mention with the next update you can save list of class, but save all properties class? i can create it but maybe is bettet wait.
     
  34. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Yes, this will be able to save all valid fields and properties.
    Valid fields are those:
    • Don't have the NonSerialized attribute.
    • Don't have the Obsolote attribute.
    • Don't have the NonSavable attribute.
    • Is not Static.
    • Is not Literal (Constant or Read-only).
    And Valid properties are those:
    • Getter & Setter Defined
    • Don't have the Obsolute attribute.
    • Don't have the NonSavable attribute.
    • Is not index property
    Yes, you are right, the documentation is small and many things aren't documented, so i decided to add many more tutorials and documentation to Save Game Pro, i have added it to the board https://trello.com/c/SgYpFsfd/35-save-game-pro, i will document everything in the Gold Update.

    I have planned to make both text-based and video-based tutorials, also, i have planned to make two version for each tutorial, the first is text-based and the second is video-based.

    Also, i have planned to include many examples inside the Save Game Pro to help the customer get started easily and fast.

    The great product should have a great documentation.

    Any further ideas and opinions are welcome. :)
    Thanks.
     
  35. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi.

    What is the load script?

    You should enable encryption for both save and load methods.

    Also, what is the error?
     
    pizzadev69 likes this.
  36. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    Wow such a fast reply.
    It just crashes without showing any errors.
    I haven't tried the encryption in loading, will try and let you know.
     
    hasanbayat likes this.
  37. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    Umm, how do I enable encryption for the load script again?

    isn't that correct?
    Code (CSharp):
    1. example = SaveGame.Load <int> (("example"), true);
     
  38. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    I'm getting this error: CryptographicException: Bad PKCS7 padding. Error found at position 25.
     
  39. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    You should pass the encryption password to the Load.
    Why aren't you enabling the Encryption globally?
    Enable Globally:
    Code (CSharp):
    1. SaveGame.Encode = true;
    2. SaveGame.EncodePassword = "myPassword";
    3. SaveGame.Save ("test", "Test value");
    4. myValue = SaveGame.Load<string> ("test");
    Enable Locally:
    Code (CSharp):
    1. bool encode = true;
    2. string encodePassword = "myPassword";
    3. SaveGame.EncodePassword = encodePassword;
    4. SaveGame.Save ("test", "Test value", encode);
    5. myValue = SaveGame.Load<string> ("test", encode, encodePassword);
    Thanks.
     
  40. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Does it work?
    Do you have any problem?
    Is there any error?

    Please report me back if it works.
    Thanks.

    EDIT: Excuse me, but we have different time locations and i am going to sleep, so i will answer all of your questions when i awake.
     
    Last edited: Oct 24, 2017
  41. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    Nope, I'm getting this:-

    Exception: Error while parsing: unable to parse; invalid token "z"; context = <zWiwDnzC2VtgwpDm6aNdohNfBwQR/7V7z2dv+cr3Co70z7A+Tm>
    FullSerializer.fsResult.AssertSuccess ()

    When I double click it, it takes me to this line in your JsonSerializer script
    Code (CSharp):
    1.                 fsData data = fsJsonParser.Parse ( reader.ReadToEnd () );
    2.  
     
  42. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Could you post your saving and loading script?
    Did you enable Encryption Globally?

    Please let me know.
    Thanks.
     
  43. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    I'll try again after I come back from work and let you know.
    Thanks a lot for following up and replying ASAP!
     
    hasanbayat likes this.
  44. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    Okay so I added this in my Start function and commented out everything else that has to do with your script.
    Code (CSharp):
    1. SaveGame.Encode = true;    
    2. SaveGame.EncodePassword = "myPassword";
    3. SaveGame.Save <int> ("test", 1);
    I'm getting this now:-
    CryptographicException: Bad PKCS7 padding. Invalid length 81.
     
  45. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    It is a strange problem.

    I have tested all encryption and such stuff, it is strange problem, but let me debug it and solve it.

    Could you post the full error message? which file and line it occurs?

    Thanks.
     
  46. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    It seems it is a bug with Encoding.UTF8.GetBytes and Encoding.UTF8.GetString, and they should be replaced with Convert.FromBase64String and Convert.ToBase64String, so for a quick fix, open the BayatGames/SaveGameFree/Scripts/Encoders/SaveGameSimpleEncoder script and replace
    Code (CSharp):
    1. Encoding.UTF8.GetString
    with
    Code (CSharp):
    1. Convert.ToBase64String
    and replace
    Code (CSharp):
    1. Encoding.UTF8.GetBytes
    with
    Code (CSharp):
    1. Convert.FromBase64String
    Source: https://stackoverflow.com/a/20319561/6838727
    Thanks.
     
  47. pizzadev69

    pizzadev69

    Joined:
    Jan 10, 2016
    Posts:
    21
    Yup, that fixed it.
    I also changed the encoding to Unicode and it worked too.
    Thanks again!
     
  48. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    I will fix it in the next update.

    Thanks for reporting back.
     
  49. vorora

    vorora

    Joined:
    Mar 17, 2015
    Posts:
    34
    Hello. Save Game Free is really good and easy to use in Editor and Stand Alone build. But recently I tried to build my game on WebGL and I couldn't save or load. I took a look at SaveGameWeb class and if I'm not wrong, it's not compatible with WebGL either. Did I do something wrong or the plugin doesn't support WebGL yet? Thanks.
     
  50. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    629
    Hi.

    The SaveGameWeb is intended to Web & Cloud save and is not just for WebGL.

    For WebGL, you can use SaveGame API to save and load game data and there is no need to use SaveGameWeb.

    Do you get any error?

    Thanks.