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.

Easy Save - The Complete Save Data & Serialization Asset

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

  1. DataportKultur

    DataportKultur

    Joined:
    May 5, 2022
    Posts:
    3
    You were right. The http:// was missing. Thank you for your great support! :)
     
    andreiagmu and JoelAtMoodkie like this.
  2. andreiagmu

    andreiagmu

    Joined:
    Feb 20, 2014
    Posts:
    148
    Maybe you could add the EasySave assembly definitions (for runtime and editor) inside a .unitypackage included in the main asset?
    That way, their installation would be optional to the user.
    Other assets use this solution to include their .asmdefs. ;)
     
    Last edited: Oct 5, 2022
    JoelAtMoodkie likes this.
  3. JoelAtMoodkie

    JoelAtMoodkie

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

    Great idea. If we find that users are having issues creating their own asmdefs then we will indeed include this option.

    All the best,
    Joel
     
    andreiagmu likes this.
  4. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,796
    Hi @JoelAtMoodki
    I noticed you added serialization/deserialization support for NativeArray, which is great
    Any plans for adding support for NativeList and NativeHashMap too?
    Thanks
     
  5. JoelAtMoodkie

    JoelAtMoodkie

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

    We've not currently added support for NativeList/NativeHashMap as they exist in a package which is not bundled with Unity, and Unity doesn't provide a reliable way of conditionally compiling based on whether a package is installed or not yet. Once there's a way of doing this, or we find a reliable way of achieving this ourselves, we'll be able to add support.

    All the best,
    Joel
     
    jGate99 likes this.
  6. moayad-jawaker

    moayad-jawaker

    Joined:
    Mar 4, 2020
    Posts:
    10
    Hello @JoelAtMoodkie
    We are using EasySave3 version 3.3.1 f10 and we are getting a lot of errors like below
    NullReferenceException: Object reference not set to an instance of an object. on function
    ES3Writer.Merge
    And it did not happen before and we did not change any line of code.
    please check the attached image from Backtrace.
    we are using unity 2019.4.16.
    Any idea what happens?
     

    Attached Files:

    Last edited: Oct 15, 2022
  7. JoelAtMoodkie

    JoelAtMoodkie

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

    As you are using a very old version of Easy Save I recommend making a backup of your project and updating to the latest version (3.5.1).

    If this doesn’t resolve your issue, and as we’ve had no other reports of this, please could you replicate this in a project containing only the bare minimum to replicate it and private message it to me with instructions.

    All the best,
    Joel
     
  8. moayad-jawaker

    moayad-jawaker

    Joined:
    Mar 4, 2020
    Posts:
    10
    Hello @JoelAtMoodkie,
    Thanks for your response, actually this is the first step that I will do, to update to the last version but this issue has not happened before.
    I will let you know if this happened after the upgrade.
    Thanks again
    Moayad
     
    JoelAtMoodkie likes this.
  9. Moayad

    Moayad

    Joined:
    Feb 28, 2016
    Posts:
    1
    Hi @JoelAtMoodkie,
    I have updated the Assets from the package manager inside the unity editor to the last version 3.5.1, download then import, but in the change log file in the assets, the last edit you added is 3.4.2, so is it missing from your side?
    please check the attached image
     

    Attached Files:

  10. JoelAtMoodkie

    JoelAtMoodkie

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

    It looks like the change log file wasn’t updated before submission, but rest assured that you’ve updated from the package Manager then you will be on the latest version.

    All the best,
    Joel
     
  11. Scalisco

    Scalisco

    Joined:
    Feb 2, 2014
    Posts:
    14
    Hi @JoelAtMoodkie ! Is the cached file settings supposed to GC Alloc whenever Save or Load is called? I am getting a lot of GC Allocs when loading and saving, and I'm pretty sure I have the cache enabled. If it's intended, then I guess we're supposed to limit how many times we call save and load in general.
     
  12. JoelAtMoodkie

    JoelAtMoodkie

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

    Caching means that the data is stored in memory, so it’s necessary to allocate memory when you save (and when you load in order to deserialise that data via a stream).

    The amount of memory allocated will be proportional to the amount of data you’ve stored in the cache.

    All the best,
    Joel
     
  13. Gatskop_Software

    Gatskop_Software

    Joined:
    Sep 21, 2014
    Posts:
    86
    Using playmaker is anybody else getting this error I did set up the PHP file and MySQL server tried to do a file sync but the documentation is outdated. Not 100% sure what to do first 1.File Exist 2.If not ES3 File Create 3. If exist ES3 Cloud Sync. When I press the button it get a file don't exist on created file I get this
    Button : FSM : State 6 : ES3FileCreate : System.ArgumentException: Extension of file in Resources must be .json, .bytes, .txt, .csv, .htm, .html, .xml, .yaml or .fnt, but path given was "SaveFile.es3"
     
    Last edited: Oct 30, 2022
  14. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    868
    Hi there, and thanks for getting in contact.

    It looks like you’re trying to load an ES3 file from resources but you’ve not given it the extension .bytes, which is a requirement at Unity’s end. Please see the Saving and Loading from Resources guide for more information:

    https://docs.moodkie.com/easy-save-3/es3-guides/saving-loading-resources/

    All the best,
    Joel
     
  15. Grasshopper2020

    Grasshopper2020

    Joined:
    Apr 5, 2020
    Posts:
    6
    Hello, apologies if this is not the right place to post, I can't see a 'create new thread' although pretty sure someone has asked this before. What is the easiest way to save score and music, and load it on any scenes please? I am a bit confused and I can't seem to find a simple example, please note my programming skills are limited, many thanks in advance
     
  16. JoelAtMoodkie

    JoelAtMoodkie

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

    You can find information on basic usage of Easy Save in the documentation:
    https://docs.moodkie.com/product/easy-save-3/

    In particular I recommend taking a look at the Getting Started guide to begin with:
    https://docs.moodkie.com/easy-save-3/getting-started/

    Regarding saving music, I assume you mean saving AudioClips. This is covered here, in the Saving audio files tab:
    https://docs.moodkie.com/easy-save-...oading-images-audio/#saving-and-loading-audio

    You can also find example projects on our forum here:
    https://moodkie.com/forum/viewforum.php?f=15

    All the best,
    Joel
     
  17. Grasshopper2020

    Grasshopper2020

    Joined:
    Apr 5, 2020
    Posts:
    6
    Thank you for this Joel, I am a bit lost, as it says to save
    • To save a value, use ES3.Save
    • To load a value, use ES3.Load however not sure where to write this exactly? I added an ES2 Auto save script to my points text, to carry it to the next scene, and I also ticked it in the Easy Save scene - I would appreciate a fast video or an example, eg.. add to game object component x or do I add it in the coin.cs script somewhere? Thank you!
     
  18. JoelAtMoodkie

    JoelAtMoodkie

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

    If you’re using Auto Save then you don’t need to call any code, and just need to follow the Auto Save guide:

    https://docs.moodkie.com/easy-save-3/es3-guides/auto-save-saving-without-code/

    You can find and example projects for Auto Save here:

    https://moodkie.com/forum/viewtopic.php?f=18&t=1468

    If you’re using code, the Getting Started guide has information on where you can call code:

    However, it largely depends on your project. In short, you can the Save code when you want to save, and the load code when you want to load. When you need to save and load is dictated by your project rather than at our end.

    You can find sample projects for code here if that helps:
    https://moodkie.com/forum/viewforum.php?f=16

    All the best,
    Joel
     
  19. Grasshopper2020

    Grasshopper2020

    Joined:
    Apr 5, 2020
    Posts:
    6
    Thank you for this, I am afraid I am still a little bit lost as I never learnt programming properly

    What I tried:

    Scene 1

    1. Added Easy Save 3 Manager to scene
    2. It has a ES3 Reference Mgr showing a Points (ES3 Prefab)
    3. ES2 Auto Save Mgr I ticked 'points' to be saved

    Scene 2

    1. Added Easy Save 3 Manager to scene
    2. It has a ES3 Reference Mgr showing a Points (ES3 Prefab)
    3. ES2 Auto Save Mgr I ticked 'points' to be saved

    Points do not transfer from Scene 1 to 2

    Also I tried

    Scene 1: adding a ES3 Prefab script to the Points prefab
    Scene 2: adding the same ES3 Prefab script

    Could you please let me know all the components required to transfer points from one scene to the other?

    I have a tight deadline for Apple (they will otherwise remove my app from the store)

    Many thanks in advance
     
  20. JoelAtMoodkie

    JoelAtMoodkie

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

    You shouldn't manually add or modify Easy Save Components on the GameObjects. You should only interact with Auto Save using the Auto Save window (Tools > Easy Save 3 > Auto Save), and ES3Prefab using the Easy Save 3 > Enable Easy Save for Prefab menu item.

    You also seem to be mentioning an ES2AutoSaveMgr Component. I suspect this might be a typo but it should be an ES3AutoSaveMgr Component.

    So that I can provide specific assistance, please could you replicate your issue in a new project with a pair of simple scenes and private message it to me with instructions.

    All the best,
    Joel
     
    Last edited: Nov 5, 2022
  21. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,434
    Hi Joel, is it possible to serialize Playmaker's FSM nodes and states with Easysave?
    My intention is to be able to mod the logic of an already published game without having to make a new build of the game.
     
  22. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    868
    Hi there, and thanks for getting in contact.

    The nodes and states of PlayMaker are not serializable at runtime, and only things such as FsmVariables are. This is because FSMs rely on types which C# provides no way of reconstructing at runtime.

    All the best,
    Joel
     
  23. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,434
    Sorry for not being more clear with the question. We don't want to serialize at runtime, we are creating the playmaker logic in the editor and want to be able to serialize it with easysave in the editor. Then upload that new logic to be used in runtime.
     
  24. JoelAtMoodkie

    JoelAtMoodkie

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

    You would still need to deserialise it at runtime, which has the same limitations.

    All the best,
    Joel
     
  25. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,434
    Ok, thanks for the clarification.

    We are also using Adventure creator Actionlists. Would this be the same situation?
     
  26. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    868
    I'm afraid I have no experience with that asset so wouldn't be able to say. However, you can find information on what types of data and fields/properties will be saved automatically with Easy Save here:
    https://docs.moodkie.com/easy-save-3/es3-supported-types/

    All the best,
    Joel
     
  27. nobluff67

    nobluff67

    Joined:
    Nov 3, 2016
    Posts:
    329
    Cut and paste from your site:

    ES3.SaveRaw("test", "myFile.txt");

    Where is the file stored? I have searched the entire project directory and can not find a file.

    EDIT: Found it, its in appdata. I thought it would be in project folder so you can load it as a resource.
     
    Last edited: Nov 17, 2022
  28. JoelAtMoodkie

    JoelAtMoodkie

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

    By default data is stored in Unity’s PersistentDataPath because this is the only place guaranteed to be writable at runtime and in a build (the project folder doesn’t exist at runtime on most platforms). If you wish to save elsewhere you can provide an absolute path instead of a relative path/filename.

    For more information on paths and storage see the relevant guide:
    https://docs.moodkie.com/easy-save-3/es3-guides/settings-paths-locations/

    All the best,
    Joel
     
    nobluff67 likes this.
  29. pontifex9355

    pontifex9355

    Joined:
    Aug 13, 2018
    Posts:
    1
    Hi Joel,

    Here's a bug I found when loading objects, tell me if it's a known issue, whether it's planned to be fixed or maybe if there are some workarounds for it:

    Let's assume this is a class structure we are dealing with:
    Code (CSharp):
    1.  
    2. public class TestScriptableObject : ScriptableObject
    3. {
    4.     public SimpleScriptableObject Simple;
    5. }
    6.  
    7. public class SimpleScriptableObject : ScriptableObject { }
    8.  
    When saving
    TestScriptableObject
    with ES3 we are using reference mode by value:

    ES3.Save(Key, ObjectToSave, new ES3Settings { memberReferenceMode = ES3.ReferenceMode.ByValue, referenceMode = ES3.ReferenceMode.ByValue });


    There is a bug when loading back that object, where loaded field
    Simple
    is deserialized as null. If you add any fields to
    SimpleScriptableObject
    it will be loaded as expected.

    So the issue is: if a ScriptableObject that has no fields is saved by value, it will be deserialized as null. I would expect that instead a new instance of that class is created.

    I've attached a simple repro project for you to checkout.

    Thanks in advance! :)
     
    Last edited: Dec 6, 2022
  30. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    868
    Hi there, and thanks for the bug report.

    In the project you sent over the 'Simple' field of the TestScriptableObject wasn't assigned, so this being saved and loaded as null was correct. However, I suspect you just forgot to assign it in the inspector, and doing so manually replicates your error :)

    This happens because your SimpleScriptableObject has no fields or properties, and currently the serializer will treat this as null when it's a reference type and saved/loaded by value. If you private message me your invoice number I'll send over an update which creates an instance rather than returning null, but you might find it easier to simply ensure that your ScriptableObject has at least one field.

    All the best,
    Joel
     
    Last edited: Dec 6, 2022
  31. KliveOne

    KliveOne

    Joined:
    Jul 28, 2015
    Posts:
    25
    Hi Joel, I have a quick question on workflow for using ES3.StoreCachedFile();

    Im having a weird time understanding the proper usage of this.

    right now my workflow is

    NOTE: ES3.CreateCache is pseudo for ES3Settings(ES3.Location.Cache);

    StartGame ->
    (A) ES3FileExists = false -> OR (B) ES3FileExists() = true
    (A) SETTINGS = ES3.CreateCache("SaveName.sav") ->
    (B) ES3.CacheFile("SaveName.sav") ->

    (Playgame and ES3.Save(key,type,SETTINGS ) ->
    then right after save ES3.StoreCache(SETTINGS)->
    right after store cache is SETTINGS = ES3.CreateCache("SaveName.sav") ->
    Save here and there as needed then loop ES3.Save(key,type,SETTING) , ES3.StoreCache(SETTINGS) , SETTINGS = ES3.CreateCache("SaveName.sav") (when needed to save) ->
    -->
    At Closegame, ES3.StoreCache(SETTINGS)


    Now somehow this seems to work in my game during the A bit , (when no save exists) , when i restart the game , this somehow doesnt seem to work
    and the cache poofes even which is odd lol.

    Any help would be great and even more great on how to propery use the cacheing system for the performance bit you mention on your site.
    I saw the site it is understandable but a test example would rock :)

    ~Shave~
     
  32. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    868
    Hi there, and thanks for getting in contact.

    Would you be able to put together a script which I can drop into a new scene in a new project which replicates your issue? Unfortunately pseudocode doesn’t tell the whole story.

    One thing you shouldn’t do is StoreCachedFile after each save call, otherwise you will negate the performance benefit of using caching.

    All the best,
    Joel
     
  33. KliveOne

    KliveOne

    Joined:
    Jul 28, 2015
    Posts:
    25
    Hellos, I sent a test scene package with the bare minimum of what im doing workflow wise.

    Thanks again for your help :)
     
  34. fengwangzi

    fengwangzi

    Joined:
    Jan 25, 2020
    Posts:
    8
    My English is not good, so I don't know if you can read the questions.
    When I have stored a data.
    Modify the code to add a new property in ES3Types.
    then read the data. It will go wrong, how to avoid this problem? How to check if the data exists before reading?
    The code is generated automatically in ES3Types.
     
  35. JoelAtMoodkie

    JoelAtMoodkie

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

    Outside of an ES3Type you use ES3.KeyExists or ES3.FileExists to check whether data exist.

    Inside of an ES3Type you use the switch statement inside of the Write method to conditionally load fields.

    All the best,
    Joel
     
  36. fengwangzi

    fengwangzi

    Joined:
    Jan 25, 2020
    Posts:
    8
    I just don't know
    Inside of an ES3Type
    how to write it, can you write an example?
    SORRY
     
  37. fengwangzi

    fengwangzi

    Joined:
    Jan 25, 2020
    Posts:
    8
    Code (CSharp):
    1. protected override void ReadObject<T>(ES3Reader reader, object obj)
    2.         {
    3.             var instance = (MC)obj;
    4.             foreach(string propertyName in reader.Properties)
    5.             {
    6.                 switch(propertyName)
    7.                 {
    8.                  
    9.                     case "Lv":
    10.                     reader.SetPrivateField("Lv", reader.Read<System.Int32>(), instance);
    11.                     break;
    12.                     case "Now":
    13.                         instance.Now = reader.Read<System.Int32>(ES3Type_int.Instance);
    14.                         break;
    15.                     default:
    16.                         reader.Skip();
    17.                         break;
    18.                 }
    19.             }
    20.         }
    How to check if the data exists before reading?Where do I insert the code?
     
  38. JoelAtMoodkie

    JoelAtMoodkie

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

    Your code is already checking if the data exists before reading. Each 'case' will only be called if the data exists.

    If you're getting an error about needing to check whether data exists before loading it, you should do this outside of the ES3Type before you call ES3.Load. I.e.

    Code (CSharp):
    1. if(ES3.KeyExists("myKey"))
    2.     myData = ES3.Load<int>("myKey");
    All the best,
    Joel
     
  39. fengwangzi

    fengwangzi

    Joined:
    Jan 25, 2020
    Posts:
    8
    Thank you very much, maybe I got the question wrong. I'll ask you again when the problem arises next time.
    It is true that I have added new data without problems, I just had problems before.I didn't know how to ask questions at that time, but now I found someone managing the forum here!:)
     
  40. WilsonCWong

    WilsonCWong

    Joined:
    Mar 20, 2013
    Posts:
    31
    I'm trying to serialize this dictionary:
    Code (CSharp):
    1. [ES3Serializable]
    2. private Dictionary<Type, IStoreCache> storeCaches;
    But it doesn't seem to serialize the Type properly. It looks like this in the JSON (Note the System.RuntimeType):
    Code (JSON):
    1.     "variableStore" : {
    2.         "__type" : "Company.Ink.VariableStore,Company.Ink",
    3.         "value" : {
    4.         "storeCaches" : {{
    5.                 "__type" : "System.RuntimeType,mscorlib"
    6.             }:{
    7.                 "__type" : "Company.Ink.StoreCache`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],Company.Ink",
    8.                 "Store" : {"peopleMet":5,"battlesLost":12,"strengthPoints":15.5
    9.                 }
    10.             }
    11.         }
    And when trying to load it back with ES3.Load, I get this error:
    Code (csharp):
    1. System.MissingMethodException: Default constructor not found for type System.RuntimeType
    2.   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00076] in <d6232873609549b8a045fa15811a5bd3>:0
    3.   at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache) [0x00009] in <d6232873609549b8a045fa15811a5bd3>:0
    4.   at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) [0x00027] in <d6232873609549b8a045fa15811a5bd3>:0
    5.   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00020] in <d6232873609549b8a045fa15811a5bd3>:0
    Any ideas what could be going on here?
     
    Last edited: Jan 2, 2023
  41. JoelAtMoodkie

    JoelAtMoodkie

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

    System.Type is an abstract class. When you create a Type in C# (i.e. by calling typeof(YourType)), it will usually be of type System.RuntimeType, which is the concrete definition for a type but is not automatically serializable at runtime.

    However, you can just create an ES3Type for System.Type instead. I've attached an ES3Type for this below which you can import into your project to automatically add support for System.Type. Note that you will also need to delete your save data to ensure the old format is not in there.

    All the best,
    Joel
     

    Attached Files:

    WilsonCWong likes this.
  42. WilsonCWong

    WilsonCWong

    Joined:
    Mar 20, 2013
    Posts:
    31
    Thanks Joel, that worked great!
     
    JoelAtMoodkie likes this.
  43. unity_A12A49FF530013E7B26

    unity_A12A49FF530013E7B26

    Joined:
    Dec 7, 2022
    Posts:
    7
    Using ES3? How can I be able to save & load image in runtime?
    Because I have this app that lets users import images.
    I want those imported images to be saved once the app was closed and loaded when the app starts again.

    Thank you
     
  44. JoelAtMoodkie

    JoelAtMoodkie

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

    Please see the Saving and Loading Images section of the docs:
    https://docs.moodkie.com/easy-save-3/es3-guides/saving-and-loading-images-audio/

    All the best,
    Joel
     
  45. ahmadcrosshair

    ahmadcrosshair

    Joined:
    Jan 2, 2023
    Posts:
    1
    @JoelAtMoodkie I have question regarding Easy Save 3 . When I want to load data from cache it replace existing data and replace with new data and it also not save data with parent can you kindly tell me about this
     
  46. JoelAtMoodkie

    JoelAtMoodkie

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

    Please could you send me a support ticket via the form at moodkie.com/contact with the code you're using to save and load from cache, and a bit more detail about what you mean by "and it also not save data with parent".

    All the best,
    Joel
     
  47. SeerSucker69

    SeerSucker69

    Joined:
    Mar 6, 2021
    Posts:
    48
    @JoelAtMoodkie What am I doing wrong when loading this list?

    I have a list:

    Code (CSharp):
    1. [SerializeField] public List<Thing> Things;         // List of all things on map
    Here is the class that the lists contains:

    Code (CSharp):
    1. public class Thing // Class to describe a thing (object) in the game eg tree
    2. {
    3.     public int ThingID;           // Pointer to Object Type
    4.     public int ThingClass;        // Type of thing class eg 1=Tree
    5.     public string Desc;           // Description of Thing            
    6.     public string Spritename;     // Name of Sprite to show thing in tile
    7.     public CellNum MyCell;        // Location x,y on map of the thing
    8.     public GameObject MyGO;       // Game Object of the Thing
    9.  
    10. }
    I can save it ok with

    Code (CSharp):
    1. ES3.Save("Things", Things);            // Save Things List
    but when I try load it with
    Code (CSharp):
    1. ES3.LoadInto("Things", Things);
    I get the following error:

    Code (CSharp):
    1. IndexOutOfRangeException: The collection we are loading is shorter than the collection provided as a parameter.
    2. ES3Types.ES3ListType.ReadInto (ES3Reader reader, System.Object obj) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3ListType.cs:105)
    3. ES3Reader.ReadInto[T] (System.Object obj, ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:292)
    4. ES3Reader.ReadInto[T] (System.String key, T obj) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:232)
    5. ES3.LoadInto[T] (System.String key, T obj, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:584)
    6. ES3.LoadInto[T] (System.String key, T obj) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:539)
    7. IsoMap.LoadMapFromFile (System.String filename) (at Assets/_Scripts/IsoMap.cs:450)
    if I put a
    Code (CSharp):
    1. Things = new();   // Create Things List
    before the load command it runs the save command without error, but the list returns empty (unloaded).

    I have tried putting a no parameter constructor in, but it still loads empty or errors as above.

    How do I load a save list?
     
  48. JoelAtMoodkie

    JoelAtMoodkie

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

    I think you misunderstand the purpose of ES3.LoadInto (see the API reference for more information). In your case you should use ES3.Load.

    All the best,
    Joel
     
  49. SeerSucker69

    SeerSucker69

    Joined:
    Mar 6, 2021
    Posts:
    48
    Thanks for your quick reply!

    I did read the API docs for ES3.LoadInto and it says "Loads the value from a file with the given key into an existing object, rather than creating a new instance" which is what I want to do, I already have my list created and cleared, ready for the load command to fill. This command works with an existing array, but errors as above for an existing list?

    When I try to use ES3.Load like this: Things = ES3.Load("Things"); it gives me the following error message "Compiler Error CS0266 Cannot implicitly convert type object to system.collections.generic.list <thing> . An explicit conversion exists (are you missing a cast?)"

    which leads us to the correct syntax of: Things = (List<Thing>)ES3.Load("Things"); I guess (might be good for you to have an example of this syntax in your docs for people trying to load and save lists?)

    So I have to use ES3.LoadInto("Map",Map); for the existing array and Things = (List<Thing>)ES3.Load("Things") for an existing list? This works, but that took a few hours, your help, and the docs didn't really guide me gently to this.
     
  50. JoelAtMoodkie

    JoelAtMoodkie

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

    Apologies, the part of the ES3.LoadInto guide which is relevant to your situation is two paragraphs below the one you quoted:

    "LoadInto can also accept an array (or List) as a parameter, and will load the data into each object in the array. The array must contain the same number of items as the array we are loading."

    When using LoadInto it expects a List populated with instances of your class to load the data into, but you've provided an empty List.

    ES3.LoadInto is a generic method where the generic parameter is the type of data you're loading. As you're not providing any parameters from which the generic parameter can be implied (e.g. the default value parameter) you must specify the generic parameter. E.g.

    Code (CSharp):
    1. Things = ES3.Load<List<Thing>>("Things");
    If we find that users are getting confused with this then we'll definitely consider adding information on how the generic works :) We tend to avoid adding things which relate more to how C# works to avoid the docs becoming bloated.

    All the best,
    Joel
     
    Last edited: Jan 22, 2023