Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Easy Save - The Complete Save Data & Serialization Asset

Discussion in 'Assets and Asset Store' started by JoelAtMoodkie, May 28, 2011.

  1. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Thanks Joel, I'll look in to that.
     
  2. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161

    Great, just bought it.
    You had me at
    "our own binary serialization which is structured in a way which makes it very quick, very powerful and require much less storage space. It allows features such as random access, and doesn't require slow reflection libraries which bloat the size of your app. It's generally obfuscated, apart from strings. If you require strings to be obfuscated, you can just encrypt them. And to confirm, Easy Save obfuscates on PlayerPrefs too."

    That's perfect, looking forward to the future GUI stuff!

    Great job!
     
  3. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    I'm testing my game in Unity 5 beta 21 using Easy Save 2.58. The editor compiles OK and I can build to iOS successfully. Xcode also builds successfully, but when playing crashes with the following error:

    Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method 'ES2FilenameData:.ctor (string,ES2Settings)' while running with --aot-only.

    at ES2Settings..ctor (System.String identifier) [0x00000] in <filename unknown>:0
    at ES2.Exists (System.String identifier) [0x00000] in <filename unknown>:0
    at RAD_GC_AutoSteering.Start () [0x00000] in <filename unknown>:0

    The line it is crashing on appears to be:

    if (ES2.Exists ("autoSteering"))
     
  4. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Unfortunately we can no longer reply to questions in this thread as we've had issues with the forum not notifying us of new replies.

    However, there's a thread on your issue here: http://www.moodkie.com/forum/viewtopic.php?f=5&t=743

    All the best,
    Joel
     
  5. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Hi... I have a question, I want to have user log feature in my game, and it should save in database server. this is for tracking the learning progress of users. what is the workflow using ES2 for achieving this purpose?
     
  6. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Please could you explain a bit more about what sort of data you need to store in the log? Is it just lines of text that you want to save? And example of a log entry would really help me to see what you're aiming to do :)

    All the best,
    Joel
     
  7. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Hii.. i just want to store data like in the table,

    Data.png
     
  8. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi again,

    If you want to save the data so that it can be read by Easy Save, the best way to do this would be to create a LogEntry class containing those fields, automatically add support for it, and then create a LogEntry and upload it like you would any other data.

    If you're intending on storing this data in a MySQL table with the same headings, you will need to modify the ES2.php file and create a WWW to communicate with it. This is because the web functionality is only intended as a data store at the moment. Adding the ability to upload to custom tables is high up on our To Do list, but we're currently tied up with working around bugs introduced by Unity in their newer versions. In the meantime, I may be able to assist you if you run into any trouble implementing it. The best thing to do is to contact me directly or create a thread on our forums, as it gets a bit difficult replying here.

    All the best,
    Joel
     
  9. Le-nain

    Le-nain

    Joined:
    Nov 26, 2012
    Posts:
    62
    Hi @joeltebbett,

    Just made my company purchase Easy Save2 and barely started using it, but I can already tell it's gonna be a great timesaver :)

    I just wanted to tell you, as far as I understood the File Editor is still under development, right? If so, this might be a known issue, but I tried to open a file where I just saved a List<> of a custom type, and when I try to preview this list (clickling on its tag in the File Editor once the file is open) I just get null refs at every refresh. It's no big deal, as it's only some display stuff (I implemented the load and it works well, so I know my data is saved/loaded correctly), but pretty annoying as once someone tries to preview it like I did and it fails, the popup can't be closed anymore (the null refs happening at every refresh befopre the close input is executed)!

    Good luck and keep the good stuff going! :)

    PS: in case you would need some more context, my class is pretty basic (one string and one int, both public) and made "manageable" by your auto Add Type button (no manual edition from my side needed).
     
  10. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there, and thanks for the purchase :)

    I've managed to replicate this at my end and it will be fixed in v2.6.3. We submitted v2.6.2 for approval on Friday, so unfortunately we won't be able to get it in that release. However, if you email us here, I'll send over the fix as soon as it's ready.

    All the best,
    Joel
     
  11. Le-nain

    Le-nain

    Joined:
    Nov 26, 2012
    Posts:
    62
    Wow, that's a quick answer :)

    Nice to read you've already pinpointed the problem.
    And thanks for the contact solution, but as I said, this is definitely not a big enough problem for me to put extra load on you in order to get the fix earlier. I just wanted to share it in order to have an overall better product and will probably be able to live with it until an official release ;)

    Just so I know, will this happen with every List<> of custom types? Maybe even every Collection? Want to know in order to not reproduce it again and again unknowingly meanwhile ^^
     
  12. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    This will currently happen with any custom type, or collection of custom types. We made a few changes to the File Editor in anticipation of Unity 5, but we inadvertently introduced this error in the process. Luckily it's an easy fix at our end.

    We'll also see about restructuring it so that when such an error occurs, it doesn't force the Editor window to stay open. Note that in the meantime, you should be able to make the window closable again by reimporting any asset (or do anything which makes Unity recompile it's scripts).

    - Joel
     
  13. Le-nain

    Le-nain

    Joined:
    Nov 26, 2012
    Posts:
    62
    Thanks for the intel, both about the source and the tmp workaround!
     
  14. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
  15. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    696
    Hey Joel.

    I am trying to use Easy Save 2 to save data in the editor, e.g when the game is not running, but I keep getting this error:


    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. ES2Writer.WriteHeader (System.String tag, Key collectionType, .ES2Type valueType, .ES2Type keyType)
    3. ES2Writer.Write[UInt16[]] (System.UInt16[] param, System.String tag)
    4. ES2.Save[UInt16[]] (System.UInt16[] param, System.String identifier)
    Any ideas? This is the code I am using to save:

    Code (CSharp):
    1.         if(GUILayout.Button("Save"))
    2.                         {
    3.                             Debug.LogError(floor.mainChunk.voxels);//sanity check, these are not null
    4.  
    5.                             ES2.Init();
    6.                             ES2.Save<ushort[]>(floor.mainChunk.voxels, ((Structures)i).ToString());
    7.                         }
    Any ideas?

    Cheers!
    Jason
     
  16. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi Jason,

    When using Save methods, you shouldn't specify the generic parameter. i.e.

    Code (CSharp):
    1. ES2.Save(floor.mainChunk.voxels, ((Structures)i).ToString());
    And just for reference, when loading an array, you should use the LoadArray method, and use the type of the data in the array as the generic parameter. i.e.

    Code (CSharp):
    1. floor.mainChunk.voxels = ES2.LoadArray<ushort>((Structures)i).ToString());
    All the best,
    Joel
     
  17. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    696
    I should have slept on it :p That worked perfectly thanks (removing the generic parameter)
     
  18. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Glad to be of help. Let me know if you run into any other problems!

    - Joel
     
  19. playa1337

    playa1337

    Joined:
    Jan 19, 2014
    Posts:
    13
    Hello, I am trying to get the custom data working. However I get the following (4) errors :

    • * /ES2UserType_hpStore.cs(32,41): error CS0030: Cannot convert type `UnityEngine.Component' to `hpStore'
    • * /ES2UserType_hpStore.cs(57,33): error CS0309: The type `hpStore' must be convertible to `UnityEngine.Component' in order to use it as parameter `T' in the generic type or method `ES2Type.GetOrCreate<T>()'
    • /ES2UserType_hpStore.cs(58,17): error CS1502: The best overloaded method match for `ES2Type.Read(ES2Reader, UnityEngine.Component)' has some invalid arguments
    • /ES2UserType_hpStore.cs(58,17): error CS1503: Argument `#2' cannot convert `hpStore' expression to type `UnityEngine.Component'
    Please find all the reference code attached : Would you be able to let me know what I can do differently to satisfy the errors?
     

    Attached Files:

  20. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    This error occurs when you change the class so that it no longer inherits from MonoBehaviour after creating the ES2Type.

    However, another problem is that Easy Save can only add support for classes with parameterless constructor, which your hpStore class doesn't have. If you want to automatically add support for it, simply add a parameterless constructor to it, and then go to Easy Save 2 > Manage Types and click Add Type again. This should fix your problem.

    Alternatively you can manually create an ES2Type for your hpStore class using the instructions here.

    All the best,
    Joel
     
    playa1337 likes this.
  21. Nabil_fx

    Nabil_fx

    Joined:
    Nov 9, 2013
    Posts:
    124
    I need help, I download Easy Save 2, no i need to upload the player name, with the score result. How i configure?
     
  22. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Not sure if you're not seeing the replies on the forum, or my reply to your email, but I've responded to this question here.

    All the best,
    Joel
     
  23. Milo_del_mal

    Milo_del_mal

    Joined:
    Jan 27, 2013
    Posts:
    43
    I was about to buy easy save, but it warned me it was done with Unity (some older version). Is Easy save fully compatible with Unity 5?
     
  24. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Easy Save is indeed fully compatible with Unity 5. For some reason the Asset Store shows that warning with any assets which support both Unity 4 and Unity 5.

    - Joel
     
  25. Mark Henderson

    Mark Henderson

    Joined:
    Oct 25, 2013
    Posts:
    41
    I think there's a bug with your built in Transform save and read code. I'm not sure what exactly I did to start seeing this error (As far as I can tell, it started when I switched from CharacterController.SimpleMove() to CharacterController.Move()). When the bug occurs, basically every call to a physics function seems to throw the error below:

    (That's the entirety of the error message.)

    I've spent a lot of time trying to figure out what happened, but I've tracked down a method that fixes the bugs (for me at least).

    By replacing the code that reads and writes the transform for each object (commented out below), and replacing it with code that just saves and reads the local position, rotation, and scale, I stop seeing the error:
    Code (CSharp):
    1.  
    2.  
    3.     public virtual void Save(ES2Writer save, string prefix) {
    4. //        save.Write(this.transform, prefix+TRANSFORM);
    5.        
    6.         save.Write(transform.localPosition, prefix+"TEST_POS");
    7.         save.Write(transform.localRotation, prefix+"TEST_ROT");
    8.         save.Write(transform.localScale, prefix+"TEST_SCALE");
    9.  
    10.     }
    11.  
    12.     public virtual void Load(ES2Reader save, string prefix) {
    13.          // Somehow this breaks layers completely.
    14. //        save.Read<Transform>(prefix+TRANSFORM, gameObject.transform);
    15.  
    16.         // This works fine tho
    17.         transform.localPosition = save.Read<UnityEngine.Vector3>(prefix+"TEST_POS");
    18.         transform.localRotation = save.Read<UnityEngine.Quaternion>(prefix+"TEST_ROT");
    19.         transform.localScale = save.Read<UnityEngine.Vector3>(prefix+"TEST_SCALE");
    20.    }
    21.  
    It's possible I'm doing something to corrupt the old transforms that only becomes apparent when your compiled code reads the saved data?
     
  26. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi Mark,

    Very unusual error given that Easy Save doesn't store any information about the layer. In fact underneath it's pretty much using the same code as you're using, except it also saves the tag.

    To check whether it's the tag which is causing the error, would you be able to add another Write/Read call beneath your custom ones to save the tag?

    Also when are you calling the Save and Load methods? Are you doing so inside a physics routine? The physics system changed for Unity 5 and it might be that you can no longer create Transforms within a physics routine, but it's not throwing a suitable error.

    We've not been able to replicate the error at our end, so it might also be useful to know which version of Unity you're using.

    All the best,
    Joel
     
  27. Mark Henderson

    Mark Henderson

    Joined:
    Oct 25, 2013
    Posts:
    41
    Joel,

    I added lines to save and read the tag, and found that the error returned. Very strange, as I had thought that tag had nothing to do with physics, and I don't modify tags anywhere in my codebase.

    My load steps are as follows (as far as I can tell it's not in any physics functions):

    1) begins in a Start() method, which starts a coroutine to wait for my gameSettings text file to load.
    Code (CSharp):
    1.  
    2. // The coroutine:
    3.     IEnumerator GetInternal(string name, SettingsDelegate callback) {
    4. //Called from a "void Start()" method
    5.         LoadSettings();
    6.         while(m_jsonSettings == null) {
    7.             yield return null;
    8.         }
    9. //This calls my load method
    10.         callback(m_jsonSettings[name]);
    11.     }
    2) In the callback for that, I load a single ES2Reader, which I pass around to load all my objects
    Code (CSharp):
    1.  
    2.         if(ES2.Exists(m_fileName+".DAS")) {
    3.             using(ES2Reader save = ES2Reader.Create(m_fileName+".DAS")) {
    4.  
    5.                 //World Objects
    6.                 int numObjects = save.Read<int>("numWorldObjects");
    7.                 for(int i = 0; i < numObjects; i++) {
    8.                     WorldObject.CreateObject(save, "worldObj"+i);
    9.                 }
    10.            }
    11.        }
    12.  
    3) in the WorldObject.CreateObject function, I first create an object from a prefab, based on the id saved in the save file. I then allow the created object to read data from the save file
    Code (CSharp):
    1.  
    2.     public static WorldObject CreateObject(ES2Reader save, string prefix) {
    3.         string settingsId = save.Read<string>(prefix+SETTINGS_ID);
    4.         WorldObject newObj = CreateObject(settingsId);
    5.         if(newObj != null) {
    6.             newObj.Load(save, prefix);
    7.         }
    8.         return newObj;
    9.     }
    10.  
    11.  
    12.     public virtual void Load(ES2Reader save, string prefix) {
    13.         transform.localPosition = save.Read<UnityEngine.Vector3>(prefix+"TEST_POS");
    14.         transform.localRotation = save.Read<UnityEngine.Quaternion>(prefix+"TEST_ROT");
    15.         transform.localScale = save.Read<UnityEngine.Vector3>(prefix+"TEST_SCALE");
    16.  
    17. // This line causes errors when enabled
    18. //        transform.tag = save.Read<System.String>(prefix+"TEST_TAG");
    19.  
    20. // This line also causes the same errors when enabled
    21. //        save.Read<Transform>(prefix+TRANSFORM, gameObject.transform);
    22.    }
    23.  
    I'm currently on Unity 5.0.1f1.

    I do know that you need to have objects actively using physics for this to happen. My game uses the standard asset Character Controller (for the NPCS) and UFPS.
     
  28. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Thanks for the info Mark,

    Firstly, I would try updating to 5.0.2p2 in case it's being caused by a known bug in Unity which has since been fixed.

    However, I think this could be because you're using a callback, which might be getting called during Unity's physics cycle when the Transform's tag or layer shouldn't be modified. I think I remember reading that the tag acts in a similar fashion to layers in Unity 5, so modifying the tag might cause the same issues as modifying the layer.

    For more information it would definitely be worth getting in touch with Unity, because this error seems to be due to assignment to the tag rather than anything Easy Save specific. Hopefully then they'll be able to shed some light on the matter and provide a better error message in the future.

    In the meantime, the best idea is to use your custom Read and Write calls until you know the exact source of the error.

    All the best,
    Joel
     
  29. Mark Henderson

    Mark Henderson

    Joined:
    Oct 25, 2013
    Posts:
    41
    Thanks for the prompt replies :)

    I don't have time this week, but I'll try and put together a minimal repro case to submit to Unity when I get a some free time.
     
  30. Mark Henderson

    Mark Henderson

    Joined:
    Oct 25, 2013
    Posts:
    41
    Is there any form of Safe load function, that can request a value that isn't in the save file, and use a default value if not?

    I'm thinking a simple function like

    Code (CSharp):
    1. T SafeLoad<T>(ES2Reader file, string tag, T defaultValue){
    2.  
    3.   if(file.TagExists(tag)) {
    4.     return file.Read(tag);
    5.   } else {
    6.     return defaultValue
    7.   }
    8. }
    I can write that in a utility function myself, but it seems like something that should be available from the default library.

    I'm really tired of adding a single new variable to save/read from a class, and having the returned error nuke my ability to read the entire save file.
     
  31. Milo_del_mal

    Milo_del_mal

    Joined:
    Jan 27, 2013
    Posts:
    43
    Thank you.... I bought the asset, it is wonderful.
     
  32. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi Mark,

    Apologies for the late reply, we received no notification that there were new replies in this thread.

    At the moment we don't have a method to do this but we'll consider adding it in the future. At current people just write the utility function as you have done.

    All the best,
    Joel
     
  33. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi All,

    Just to let you know that Easy Save now supports exporting to spreadsheets/Excel using our ES2Spreadsheet functionality. It currently exports CSV, but might consider adding other formats if there's demand for it.

    Documentation for it can be found HERE, and API Reference HERE.

    Thanks,
    Joel
     
  34. recagonlei

    recagonlei

    Joined:
    Feb 27, 2014
    Posts:
    11
    Hi,
    How can i set the default folder to be "Documents" automatically in all users?
     
  35. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Because the Documents path is different for every user, this will need to be set at runtime.

    The best way to do this would be to put System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) into a static string in Awake(), and then prepend this to your path in the ES2 calls. Something like:

    Code (CSharp):
    1. public PathClass : MonoBehaviour
    2. {
    3.     public static string path;
    4.  
    5.     public void Awake()
    6.     {
    7.         path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+"/";
    8.     }
    9. }
    And then your ES2 calls would look something like this:

    Code (CSharp):
    1. ES2.Save(123, PathClass.path+"myFile.txt");
    2. int myInt = ES2.Load<int>(PathClass.path+"myFile.txt");
    All the best,
    Joel
     
    recagonlei and Kiori like this.
  36. recagonlei

    recagonlei

    Joined:
    Feb 27, 2014
    Posts:
    11
    Thanks Joel!!
     
  37. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    I'm having a problem saving audio data.

    In the game, the player can record some audio data as a .wav. They are generated at runtime and saved in the /Assets folder, and then loaded into an audio clip with WWW. When I go to save them with easysave, though, I get the error that the object does not exist. This is despite me checking that the audioclip exists. doing audioclip.name even correctly puts its name in the console, but easysave still says that the file does not exist.

    I also as a test tried to put an audio clip onto the script I'm saving this stuff with and used EasySave to correctly save that clip. So it's just with the ones generated at runtime. I've also tried assetdatabase.refresh and assetdatabase.saveassets to force the editor to load the clip, but it still doesn't save

    [EDIT]

    I've changed how I'm doing things now. I create the .wav file and save it to my persistentdata path, load it with WWW into an audioclip on a script, and then try to save that audioclip with easysave. I still get the error
     
    Last edited: Aug 18, 2015
  38. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Apologies for the late reply ... the forum didn't notify me of new messages to this thread.

    Sounds like it could be that the type list isn't updating. Please could you go to Assets > Easy Save 2 > Manage Types and press Refresh ES2Init to manually update the type list to see if this fixes your problem?

    If this doesn't fix it, please could you post the exact error message that you're getting, and the code that you're using, so I can try it at my end?

    All the best,
    Joel
     
  39. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    Hi i try convert
    ES2.load to
    ES2Reader reader
    how i know if text exist
    ES2Reader.Create("save.txt")
    like
    !ES2.Exists("lvl")
     
  40. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    If you're using tags, you can use reader.TagExists(tag) to check if a tag exists in the file.

    All the best,
    Joel
     
  41. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    cool i will check that's
    and about list resize it's say error message sometime
    any idea about that's
     
  42. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    I'm not sure what you mean by 'list resize'.

    All the best,
    Joel
     
  43. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Inside Editor, there is an option: Encrypt Data. If I set it on, do I have to use the suffix &encrypt=true and &password=mypass on the ES2.Save string? or it is automatically handled?

    Whats the difference between setting Encrypt Data there and on ES2.Save/Load functions?
     
  44. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    The Encrypt Data option in settings sets it so that encryption is on by default unless otherwise specified, so you won't need to specify the encrypt=true part.

    All the best,
    Joel
     
  45. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Nice! but when I changed to this way. I'm having this error when I go to Easy Save 2 -> File Editor. I removed all suffix from ES2.Save/Load



    Edit: I added the suffix back and the error is gone. A bug, maybe?
     
    Last edited: Oct 8, 2015
  46. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    Are you using the latest version of Easy Save? I don't appear to be getting this bug at my end at the moment.

    All the best,
    Joel
     
  47. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,152
    Hello, I was looking for an ES2Reader.Skip method but there doesn't appear to be any. Any plans to add this?

    To be honest I'm not sure if this is needed, I'm trying to develop the backbone for my save system and one thing I want to be able to do is handle different save file versions (using sequential saving/loading).

    Let's say save version 3 has two int values for some class X, but in version 4 class X is removed (unlikely but theoretically it could happen, right?). Since class X no longer exist, I need to be able to skip over those two int values that exist in the version 3 save file.

    I'm sure I could probably just do a read that doesn't assign to anything, but I would think some sort of skip method would be more performant.

    Or perhaps there is a better way to go about this, which I'd certainly be open to learning about.

    Either way, thanks for your time!
     
  48. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi there,

    I've actually written a post on our forums here which explains what I find is the easiest way to support multiple versions, by creating a custom ES2Type. And from a performance perspective, you really can't get any faster than this.

    All the best,
    Joel
     
  49. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,152
    Thanks Joel, that is definitely good information, however, it seems to really only focus on how to handle adding new info.

    What happens if in a new version I remove some feature and some piece of data from the save file is no longer used. Again, it's unlikely, and obviously a Read operation that doesn't assign its return value to anything would work, but I still feel like a Skip(x) method (where x is the number of values in the file to skip) would be useful. Would this be difficult to implement, or is it a bad idea?

    Regards,
    Kyle Gillen
     
  50. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    896
    Hi Kyle,

    A skip method wouldn't be possible as the data is saved sequentially to improve performance, so there would be no way of knowing how far to skip.

    However, now that I think of it, the solution to manage deleted variables is even easier than the solution I describe in that thread. You will simply need to load the data, but not assign it to anything. For example, if the reader.Read calls in your ES2Type looked like this:

    Code (CSharp):
    1. data.a = reader.Read<int>();
    2. data.b = reader.Read<string>();
    3. data.c = reader.Read<float>();
    If you deleted variable b from your script, the reader.Read calls in your ES2Type would need to look like this:

    Code (CSharp):
    1. data.a = reader.Read<int>();
    2. reader.Read<string>();
    3. data.c = reader.Read<float>();
    This alone would also mean that you would always need to save a string, even after you've deleted the variable. However, if you also implement a version number as in the thread I linked, then you can easily work around this.

    All the best,
    Joel