Search Unity

Easy Save - The Complete Save Data & Serialization Asset

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

  1. projectcity3d

    projectcity3d

    Joined:
    Jun 11, 2019
    Posts:
    7
    Hi, can ease save 3 provide to me function to save class with arrays of subclasses? Example:
    Code (CSharp):
    1.  public class classA
    2.     {
    3.         public int par1;
    4.         public int par2;
    5.  
    6.         public classB[] bClassesArray;
    7.  
    8.         public class classB
    9.         {
    10.             public int par1;
    11.             public int par2;
    12.  
    13.             public classC[] cClassesArray;
    14.  
    15.             public class classC
    16.             {
    17.                 public int par1;
    18.                 public int par2;
    19.             }
    20.         }
    21.     }
    I need to save Class A with all parameters and parameters in all subclasses
     
  2. JoelAtMoodkie

    JoelAtMoodkie

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

    This is indeed possible, and can be achieve with the basic ES3.Save and ES3.Load methods. I.e.

    Code (CSharp):
    1. ES3.Save<ClassA>("key", value);
    2. value = ES3.Load<ClassA>("key");
    I also recommend looking at the Supported Types guide to see what fields and types are supported: http://docs.moodkie.com/easy-save-3/es3-supported-types/

    All the best,
    Joel
     
    Last edited: Mar 28, 2020
  3. projectcity3d

    projectcity3d

    Joined:
    Jun 11, 2019
    Posts:
    7
    Got it, thanks.
     
  4. barbamix

    barbamix

    Joined:
    Apr 6, 2018
    Posts:
    15
    Hi.

    I want to save my Character's position and it seems I'm missing something or it's just some kind of a bug?

    When I put my Character as a regular Sphere and save it, it saves and loads the Sphere position. But when I change the Sphere with my Character prefab it doesn't update the position after loading. It also for some reason doesn't save other non Character related integer variables. I turned on Enable Easy Save for Prefab option. What else am I missing?

    If someone is interested here's a package that I'm testing on... [link removed]
     
    Last edited by a moderator: Apr 6, 2020
  5. BIKTOP

    BIKTOP

    Joined:
    Nov 23, 2016
    Posts:
    6
    Hello. I have problems with save. At first I did the save through simple ES3.Save and ES3.Load. In this way, I saved simple data of int, string and float types. After I made saving all the data I needed, the project became very slow. I tracked the reason, the fault of all the conservation through the above described method. Then I started looking for other save methods through your plugin. I decided to use this method: https://docs.moodkie.com/easy-save-3/es3-guides/caching-using-es3file/
    Performance has increased significantly, but this does not work on devices. When I restart the game, there is no data stored in the file. And there are no keys either. When calling the file.Sync () method, an error appears: IOException: Cannot create /data/app/com.Playway.FarmFix2020-1/base.apk because a file with the same name already exists.
    In this case, an error appears only if before that something is saved to a file. If you do not save and call file.Sync (), then there are no errors.
    Please tell me which save method to use so that the application does not slow down when saving and loading, and why saving on this guide (https://docs.moodkie.com/easy-save-3/es3-guides/caching-using-es3file/) does not work
     
  6. JoelAtMoodkie

    JoelAtMoodkie

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

    Please could you show me the code you are using to save and load? Judging by the error, it looks like you're trying to save to Application.dataPath, which cannot be stored to on Android (see https://docs.unity3d.com/ScriptReference/Application-dataPath.html). Instead you should use Application.persistentDataPath, which is the default location Easy Save uses.

    All the best,
    Joel
     
  7. JoelAtMoodkie

    JoelAtMoodkie

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

    I've replied to your PM.

    All the best,
    Joel
     
  8. BIKTOP

    BIKTOP

    Joined:
    Nov 23, 2016
    Posts:
    6
    Code (CSharp):
    1. [SerializeField]
    2.     public ES3SerializableSettings settings;
    3.     private void Awake()
    4.     {
    5.         settings.location = ES3.Location.File;
    6.         settings.directory = ES3.Directory.PersistentDataPath;
    7.         instance = this;
    8.  
    9.         file = new ES3File("myFile.es3", settings);
    10.  
    11.              Debug.Log(file.GetKeys());
    12.  
    13.  
    14.         Load();
    15.     }
    16. public void SyncFile()
    17.     {
    18.  
    19.         file.Sync(settings);
    20.  
    21.     }
    22.  
    23.     public void Save()
    24.     {
    25.    
    26.         file.Save<float>(farmerProfile.name + "Cash", farmerProfile.cash);
    27.         file.Save<int>(farmerProfile.name + "Rank", farmerProfile.rank);
    28.         file.Save<int>(farmerProfile.name + "RankExp", farmerProfile.rankExp);
    29.         file.Save<int>(farmerProfile.name + "Corn", farmerProfile.cornSeeds);
    30.         file.Save<int>(farmerProfile.name + "Whead", farmerProfile.defaulfSeeds);
    31.         file.Save<float>(farmerProfile.name + "RedPaint", farmerProfile.redPaint);
    32.         file.Save<float>(farmerProfile.name + "BluePaint", farmerProfile.bluePaint);
    33.         Debug.Log("ProfileSaved");
    34.     }
    35.  
    36.     public void Load()
    37.     {
    38.         if (file.KeyExists(farmerProfile.name + "Cash"))
    39.         {
    40.             farmerProfile.cash = file.Load<float>(farmerProfile.name + "Cash");
    41.             farmerProfile.rank = file.Load<int>(farmerProfile.name + "Rank");
    42.             farmerProfile.rankExp = file.Load<int>(farmerProfile.name + "RankExp");
    43.             farmerProfile.cornSeeds = file.Load<int>(farmerProfile.name + "Corn");
    44.             farmerProfile.defaulfSeeds = file.Load<int>(farmerProfile.name + "Whead");
    45.             farmerProfile.redPaint = file.Load<float>(farmerProfile.name + "RedPaint");
    46.             farmerProfile.bluePaint = file.Load<float>(farmerProfile.name + "BluePaint");
    47.             Debug.Log("ProfileLoaded");
    48.         }
    49.  
    50.     }



    I entered the settings myself via the script and an error has disappeared (IOException: Cannot create /data/app/com.Playway.FarmFix2020-1/base.apk because a file with the same name already exists).

    However, the data is still not saved. I call Save() then Synk() and exit the game. When I return to the game, the data is not available.
     
  9. JoelAtMoodkie

    JoelAtMoodkie

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

    Just to check, have you put a Debug.Log call in your SyncFile() method just to check that it is indeed being called?

    All the best,
    Joel
     
  10. BIKTOP

    BIKTOP

    Joined:
    Nov 23, 2016
    Posts:
    6
    Yes. I put it on the button and definitely call it every time after saving. There used to be an error when calling. Now I call with my settings in which PersistentDataPath is set and there is no error. But the data is not saved
     
  11. JoelAtMoodkie

    JoelAtMoodkie

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

    If you private message me your invoice number, I'll send over a version of the Unity package which outputs debugging information which should hopefully show us where it is failing.

    Also if you haven't done so already, ensure you're using the latest version of Easy Save from the Asset Store (a new update was released on Tuesday).

    All the best,
    Joel
     
  12. BIKTOP

    BIKTOP

    Joined:
    Nov 23, 2016
    Posts:
    6
    Yes, I have the latest version of the plugin. I sent you a invoice number in the mail
     
  13. K0ST4S

    K0ST4S

    Joined:
    Feb 2, 2017
    Posts:
    35
    Hello. How to use global references prefab?
     
  14. JoelAtMoodkie

    JoelAtMoodkie

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

    We've not yet added support for Global References, so at the moment the Global References prefab will do nothing. We're waiting to find out whether Unity plans on fixing an issue at their end before proceeding.

    All the best,
    Joel
     
    K0ST4S likes this.
  15. cmart

    cmart

    Joined:
    Jul 10, 2012
    Posts:
    121
    Hi there, just picked this up and so far it is working quite nicely. I am getting an error though, not sure it is causing any issues but still curious what is going on. I am getting

    "FormatException: File is not valid JSON. Expected '{' at beginning of file, but found X"

    *(X is something different most times)

    Any idea what is going on? Right now Im just saving a few ints, and a list of scriptable objects. I did add the scriptableObject script to the types list. Im using Unity 2019.3.6f1 if that helps. Thanks for any info on this.
     
  16. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    Can you read multiple json variables from one file? Is this formatting valid in Easy Save? If so, how do you pull it?

    Example .) A file that stores all the info for all the countries in a game.

    Code (CSharp):
    1.  
    2. Nazi Germany = {
    3.     "LeaderName":{"__type":"System.String","value":"Adolf Hitler"}
    4.     "GovernmentType":{"__type":"System.String","value":"Fascist"}
    5. }
    6. United States = {
    7.     "LeaderName":{"__type":"System.String","value":"FDR"}
    8.     "GovernmentType":{"__type":"System.String","value":"Democratic Republic"}
    9. }
    10. United Kingdom = {
    11.     "LeaderName":{"__type":"System.String","value":"Winston Churchill"}
    12.     "GovernmentType":{"__type":"System.String","value":"Parliamentary Republic"}
    13. }
    14.  
    Thanks!
     
  17. JoelAtMoodkie

    JoelAtMoodkie

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

    Would you be able to show me the code you're using to save and load? Feel free to private message this to me if you're not comfortable sharing this in this thread.

    All the best,
    Joel
     
  18. JoelAtMoodkie

    JoelAtMoodkie

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

    The easiest way to represent something like this would be to make a class or struct with your fields. I.e.

    Code (CSharp):
    1. public class Country
    2. {
    3.     public string LeaderName;
    4.     public string GovernmentType;
    5. }
    You can then create one of these for each of your countries and save each one to a different key. I.e.

    Code (CSharp):
    1. ES3.Save<Country>("United Kingdom", ukCountryClass);
    2. ES3.Save<Country>("United States", usCountryClass);
    3. // etc
    Or if you don't need to randomly access them from the file, you could simply save a Dictionary of them.

    All the best,
    Joel
     
  19. cmart

    cmart

    Joined:
    Jul 10, 2012
    Posts:
    121
    Sure, thanks for checking this out. in my title screen I have a very simple manager script with this in start:

    Code (CSharp):
    1.  
    2.             if (ES3.KeyExists("PlayerHP"))
    3.                 HP = ES3.Load<int>("PlayerHP");
    and then two UI Buttons, if player clicks continue it triggers
    Code (CSharp):
    1.    
    2.         SceneManager.LoadScene(1);
    but if they click new game, it triggers
    Code (CSharp):
    1.  
    2.         ES3.Save<int>("PlayerHP", startingHP);
    3.         SceneManager.LoadScene(1);

    and then in the next scene, on the player stats script in the the start function I have this
    Code (CSharp):
    1.  
    2.         if (ES3.KeyExists("PlayerHP"))
    3.             CurrentHP = ES3.Load<int>("PlayerHP");


    I took out all the scriptable objects stuff for now to test, and I am still getting the same error.

    In this case, it is this every time.

    FormatException: File is not valid JSON. Expected '{' at beginning of file, but found '�'.


    The saving and loading of the int does work though, at least in editor (haven't tested build yet). But still feel a little cautious seeing errors :)

    Edit: here is all the console output:

    FormatException: File is not valid JSON. Expected '{' at beginning of file, but found '�'.
    ES3Internal.ES3JSONReader..ctor (System.IO.Stream stream, ES3Settings settings, System.Boolean readHeaderAndFooter) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:39)
    ES3Reader.Create (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:322)
    ES3.Load[T] (System.String key, T defaultValue, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:306)
    ES3AutoSaveMgr.Load () (at Assets/Plugins/Easy Save 3/Scripts/Auto Save/ES3AutoSaveMgr.cs:45)
    ES3AutoSaveMgr.Awake () (at Assets/Plugins/Easy Save 3/Scripts/Auto Save/ES3AutoSaveMgr.cs:64)
     
  20. JoelAtMoodkie

    JoelAtMoodkie

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

    Judging by the output you also have objects which are being saved using ES3AutoSave, so check that these aren't saving to the same file.

    If this doesn't resolve the issue, the error you're getting is most commonly caused because you're trying to read from a file which has had encrypted data written to it. Firstly, check that there's nowhere else in your code where data is being written to the file with encryption enabled. You might also want to try deleting your save data (Window > Easy Save 3 > Tools > Clear Persistent Data Path), just in case encrypted data has previously been written to the file.

    All the best,
    Joel
     
  21. cmart

    cmart

    Joined:
    Jul 10, 2012
    Posts:
    121
    Ah ok, I cleared out the persistent Data but Im still getting the error.

    I do have the Easy Save Manager 3 object in my scenes, but I don't have any objects using autosave (or at least I haven't attached that script to anything). I don't plan on using auto save, so is it safe to remove the "ES3 Auto save Mgr" script from Easy Save Manager 3 gameobject?

    I am using encryption, I set it up under "Runtime settings" in the easy save window.
     
  22. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    914
    If you're not using Auto Save then you're safe to delete the ES3AutoSaveMgr from the Easy Save 3 Manager.

    Would you be able to try these, then delete your save data, and see if this resolves the issue?

    And if this doesn't resolve your issue, please could you private message me a basic project which replicates this?

    All the best,
    Joel
     
  23. cmart

    cmart

    Joined:
    Jul 10, 2012
    Posts:
    121
    Ok think I solved it. I turned encryption off, cleared out the persistent data, turned encryption back on before I wrote anything to the new persistent data, and now Im not getting the error :) thanks for the help!
     
    JoelAtMoodkie likes this.
  24. cmart

    cmart

    Joined:
    Jul 10, 2012
    Posts:
    121
    Thanks for your help, but now I seem to have a new problem. I have a list of scriptable objects I am trying to save. I have made a few .assets of these scriptable objects, and have a public list I drag these into in the inspector I use to create the list. Some of the data does get saved, strings/ints/floats and bools, but I have some references to audioclips and sprites that are being lost. Also, instead of having the name of the .asset file, it just has a generic name in the list populated from the saved list. so instead of say "Sword Attack(AttackTemplate)" its just "(AttackTemplate)" AttackTemplate being the name of scriptable object class.

    Also getting this warning multiple times since adding scriptable object list:

    Reference with ID (multiple different IDs) could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene.


    Here is the code I am using
    Code (CSharp):
    1.  
    2.           ES3.Save<List<AttackTemplate>>("PlayerAttacks", AttacksToGive);
    3.            PlayerAttacks = ES3.Load<List<AttackTemplate>>("PlayerAttacks");
    Thanks again for any advice, I truly appreciate it :)
     
    RemDust likes this.
  25. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    Thanks,
    I ended up using a CSV and it seems to work fine.
     
  26. JoelAtMoodkie

    JoelAtMoodkie

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

    If you've already tried pressing the Refresh References button, would you be able to private message me a basic project and instructions to replicate this so I can see what is happening?

    All the best,
    Joel
     
  27. zetaxbr

    zetaxbr

    Joined:
    May 17, 2016
    Posts:
    22
    Hello Easy Save Support,

    First of all ty very much for this awesome tool for ppl like me that uses Playmaker and have 0 coding skills.
    I'm working in a project using Easy Save 2 and Unity 2018, save system are working 100% in editor and PC but when I tested in an Android device the save seems doenst work.

    Theres support to ES2 in Unity 2018 Android? Can you help me please? I didnt understands the new ES3 methods for playmaker thats why I'm using ES2.
     
  28. JoelAtMoodkie

    JoelAtMoodkie

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

    Easy Save 2 and 3 indeed work with Android. Could you let me know if anything is being outputted to the Android console? Usually an error will be thrown if an issue occurs.

    Also just to check, when are you saving?

    All the best,
    Joel
     
  29. zetaxbr

    zetaxbr

    Joined:
    May 17, 2016
    Posts:
    22
    Ty for fast reply.. here the errors and my first scene actions for ES2


    Game Stuck at first scene (the scene with data controller) if I remove it the game run first time.. then frozen last next time. if I clear data.. game works again, seeems something in ES data.
     
  30. JoelAtMoodkie

    JoelAtMoodkie

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

    Please could you show me the actions you’re using to load and create?

    All the best,
    Joel
     
  31. zetaxbr

    zetaxbr

    Joined:
    May 17, 2016
    Posts:
    22


    I always used this method for my past games with no problem, but I was using Unity 2017 (Now I was using Unity 2018 and 2019)with ESave 2.8.4. Tried upgrade ESave to lastest version from Asset Store but didnt worked either.
     
  32. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    914
    Hmm, I'm not able to tell what is happening from this. Could you private message me a basic project and instructions to replicate this at my end?

    All the best,
    Joel
     
  33. zetaxbr

    zetaxbr

    Joined:
    May 17, 2016
    Posts:
    22
    I will send an email with a part of project and my invoice, thank you!
     
  34. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    306
    Hello, Im trying to save a ScriptableObject:

    Code (CSharp):
    1. ES3.Save<ScriptableObject>("ZNETestCharacter", this.characterData);
    And Im getting the following error:

    Code (CSharp):
    1. InvalidOperationException: An Easy Save 3 Manager is required to load references. To add one to your scene, exit playmode and go to Assets > Easy Save 3 > Add Manager to Scene
    My ScriptableObject just has a string and a dictionary:
    Code (CSharp):
    1. public class ZNECharacterData : ScriptableObject {
    2.     public new string name;
    3.     public Dictionary<string, float> blendshapesDictionary;
    4. }
    Why is it requiring a Manager?
     
  35. JoelAtMoodkie

    JoelAtMoodkie

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

    This is because ScriptableObjects are UnityEngine.Object reference types, and these will be stored by reference and value.

    Also just a note, you should use the type of the ScriptableObject as the generic parameter when saving. I.e.

    Code (CSharp):
    1. ES3.Save<ZNECharacterData>("ZNETestCharacter", this.characterData);
    All the best,
    Joel
     
  36. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Hello,

    I'm trying those Playmaker actions that allow one to Save All / Load All.
    First of all, I have not found any documentation about them on the website.
    Secondly, there seems to be two bugs in the Save All action (I have the latest version of ES3).
    1. attempting to override the default saving parameters is entirely ignored (Override Default Settings) and it will use these default settings to produce a SaveData.es3 file no matter what (if that's the default name in the settings).
    2. it does save FSM vars but if you tick the Global vars box, it throws errors.
    Finally, the Load action doesn't take into account the override block either: I forced the action to use a different file (path), an encryption, a different password, etc.; all were ignored as if this code block isn't even parsed. However it does properly read the default file, for sure.

    I also have a suggestion.
    Both FSM and Global vars can be put into categories, which is an efficient way to filter vars. It would be veeerrry useful to be able to directly target the vars in categories and be able to add as many categories as possible.
    Some actions do things like that, being dynamic so the user can add custom quantities of vars like Set Multi Int Value for example. In this case, the categories would require an array of strings.
    Important detail: the default category contains no name, the string is empty. This applies to both FSM and Global vars. This means if you push a var into a custom category but then delete the name in the var's category field, it will be moved back to the default list.
    So as an example, if a user wanted to load two categories, the default one and, say, myPreciousData, two string fields would need to be added: one empty for the default vars, and one with "myPreciousData" for the custom category.
    I might have suggested a check to see if the user entered duplicate entries (the same category added to the list twice or more) but that may require too much real time parsing in Playmaker, so perhaps it could be left to the user's responsibility to avoid doing this mistake, which might throw an error at Runtime btw.
     
  37. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    914
    Hi there, and thanks for getting in touch.

    We've not currently documented them as we wait for feedback from our testers before making them public. This is because during the testing phase we often make changes to how it works.

    We recently released an update to fix this (which is the same issue as you were having with the Load action), so updating from the Asset Store will resolve your issue.

    Would you be able to show the full stack trace for the error you're getting? I don't seem to be able to replicate this at my end. If you could also send me a screenshot of the list of local variables you're saving and global variables, that will also help me determine what is happening.

    Thanks for the suggestion and the detailed information. This is actually the first time I've been made aware of categories, and I agree that this would be useful to the Save All and Load All actions to support. I've added a feature request for this here, but as it theoretically shouldn't be too difficult for us to implement this will be quite high on our to-do list.

    All the best,
    Joel
     
  38. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    In retrospect I wondered where I got these actions from and wondered too if they were recent additions. If the issue was known, good.
    For the bug I'd start a new project, clean, PM and ES3 only and see if I can replicate it first.
    I had checked the Globals' asset because sometimes PM has a bug where some Globals find themselves to be duplicated and this is bad, it's not even supposed to be possible, so you can find yourself with two identical variables, name type all that, but one is the real one as it is properly referenced with its number of uses throughout the scene, the other returns 0 uses. Yet when you delete that bad one directly from the list, the good one becomes afflicted with the "0 uses" quality.
    The only way to solve this properly has been for me to edit the file with a text editor.
    So the file is now clean and the bug is still there. This is why I'm going to do a clean test project within the next two days and see if the issue is there too. In which case I'll send the full data.
     
  39. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I'm in phase of optimization of some parts of the PM code.
    Saving data can be time consuming so these are processes one would rather do outside of any activity that would be detrimental to the user's experience of the application, at specific times like in-app pause, in-app transition, system pause or system quit.

    I just did a test to see if I could do a complete or semi-complete in-app saving phase as the user navigates to different parts of the app or through menus, without him noticing anything (with no visible impact on the frame rate).
    The idea was to spread multiple saves (to the same single stored file) over several frames, so it would allow for a smoother albeit longer saving process. The idea was to cram such an extended saving process during a transition, hoping it would eat something like 10-30ms per frame only and allow for the transition to proceed in a still sufficiently fluidic manner, with no hiccups.

    Unfortunately the Save action clearly seems to call a lot of functions, orders or whatever, beyond simply writing a value in a stored file; so much that every frame, a whole process seems to be redone around the writing itself, making each frame take much more time than what I was aiming for in the test.

    Would you have any idea how I could do a "smooth save" over several frames, with deciding how many saves to the file in storage I want to do per frame, or how many frames I want to skip (say, like with a save every two or three frames)?
     
  40. JoelAtMoodkie

    JoelAtMoodkie

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

    Everytime you save or load a key to a file using ES3.Save/Load, it opens a file stream for that file. This is likely what is causing the slowdown.

    However, we provide caching to allow you save/load data with only a write/read to file. To do this, simply set the save location to Cache for each of your actions, and then when you’re ready to store the data, use the Store Cached File action. To load a file into the cache, use the Cache File action.

    All the best,
    Joel
     
  41. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    Does Easy Save 3 work with Windows Universal Platform?
     
  42. JoelAtMoodkie

    JoelAtMoodkie

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

    Easy Save indeed works with UWP.

    All the best,
    Joel
     
    Razputin likes this.
  43. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hey @JoelAtMoodkie, I have a question about something I've run into
    I'm trying to save a type that contains a subclassable property; the property saves correctly, but I'm curious how I can restore the original type when loading so that I don't lose data?

    So I try to save SavedItemActor which contains Item.SaveData, which can be a subclass
    Code (CSharp):
    1.   public struct SavedItemActor {
    2.  
    3.     public Item.SaveData itemData;
    4.  
    5. }
    Item.SaveData has several subclasses depending on the item type. The subclass data is saved correctly as I can view it in the save file.

    The reader for this type, however, creates an instance of the base class regardless of what was saved; is there a workaround? I tried saving the typename and using Activator.CreateInstance with reader.ReadInto; that works to create the subclass, but only the base class type's data is read from the save file:

    Code (CSharp):
    1.           case "itemData":
    2.             instance.itemData = Activator.CreateInstance(Type.GetType(instance.itemDataType))as CB.Items.Item.SaveData;
    3.             reader.ReadInto<CB.Items.Item.SaveData>(instance.itemData);
    Any ideas? I appreciate you looking into this
     
  44. JoelAtMoodkie

    JoelAtMoodkie

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

    When you create an ES3Type for your class, fields are serialised strictly because it's not possible to determine the type of the field (as type data is not stored when you save, because the ES3Type defines this).

    If you want inheritance to be handled automatically, you shouldn't create an ES3Type and instead allow Easy Save to manage it.

    All the best,
    Joel
     
    greengremline likes this.
  45. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    Hi, quick follow up for some reason I'm experiencing the below error, it's caused by this block of code.

    As you probably know UWP restrict which locations you can read/write from.
    This seems like it's going to the persistentDataPath to me, but maybe easy save 3 is doing something I'm not aware of or I messed up somewhere.

    Sidenote : I did run it with LoadSaveFiles() commented out and it still threw this error, and the script works on Windows/Mac/Linux.

    Code (CSharp):
    1.    
    2.             string subDir = Path.Combine(Application.persistentDataPath, "Saves");
    3.             string path = Path.Combine(subDir, curSaveSelected);
    4.             if (!File.Exists(path))
    5.             {
    6.                 ES3.Save<string>("FileName", curSaveSelected, path);
    7.                 SaveManager.curSaveFileName = Path.GetFileNameWithoutExtension(path);
    8.                 LoadSaveFiles();
    9.             }
    10.             else
    11.             {
    12.                 Debug.LogError("Save file name already in use.");
    13.             }
    14.  
    Untitled.png
     
    Last edited: May 13, 2020
  46. JoelAtMoodkie

    JoelAtMoodkie

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

    By default Easy Save stores to persistent data path, so you don't need to create your own path, you just need to specify a filename.

    All the best,
    Joel
     
  47. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Perfect, that fixed it - thanks so much!
     
  48. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    Thanks for the help, it works now it was my string = Path.Combines it didn't like.

    I decided to stop using the strings and to navigate with just Path.Combine and default data path as you suggested.

    Code (csharp):
    1.  
    2. if (curSaveSelected != null && curSaveSelected != "")
    3.         {
    4.             if (!File.Exists(Path.Combine(Application.persistentDataPath, curSaveSelected)))
    5.             {
    6.                 ES3.Save<string>("FileName", curSaveSelected);
    7.                 SaveManager.curSaveFileName = Path.GetFileNameWithoutExtension(Path.Combine(Application.persistentDataPath, curSaveSelected));
    8.                 LoadSaveFiles();
    9.             }
    10.             else
    11.             {
    12.                 Debug.LogError("Save file name already in use.");
    13.             }
    14.  
     
    JoelAtMoodkie likes this.
  49. JoelAtMoodkie

    JoelAtMoodkie

    Joined:
    Oct 18, 2009
    Posts:
    914
    If you wanted to simplify your code further, you can use ES3.FileExists(filename) to check whether the file exists, rather than constructing your own path.

    All the best,
    Joel
     
  50. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi @JoelAtMoodkie

    Is there a way to permanently disable the "updating reference"? It takes 5-10 seconds to save and even cancelling it causes it to pop up again. :(

    It takes the same 5- 10 seconds when entering play mode as well.

    I tried to disable it with this , but no luck. Easy Save still forces the update.

    You can see a video of how long it takes for Easy Save to update.


    Thanks for your help!

    Also I've been trying to use @alexeyzakharov 's FAST ENTER PLAY mode, is Easy Save compatible with his tool? This is his forum link.
    https://forum.unity.com/threads/configurable-enter-play-mode.768689/
     

    Attached Files:

    Last edited: May 17, 2020