!!!FIXED!!! - A lot of problems :/ (not anymore :D)

Discussion and help for Easy Save 3
Paradox
Posts: 12
Joined: Wed Mar 29, 2023 11:59 am

Re: A lot of problems :/

Post by Paradox »

Hey,

thanks for the response. The docs dont really mention what this appropriate time is but I am using it when I change the scenes or when the player quits the game.

And one thing I didnt really get yet is:
What does ES3.CacheFile(); and ES3.StoreCachedFile(); without any parameters do? Does it save all the parameters inside the cache?
If you remember I have multiple save slots each with a different path ID.

If its no problem for you could you give me an example on how to save the cache file via these 2 methods you mentioned. Even though I read the Improving Performance guide multiple times it still doesnt really work. I probably have implemented ES3.StoreCacheFile wrong but currently I just did this:

Code: Select all


public void Save()
{
	Debug.Log("Save");

	ES3.StoreCachedFile();
}

Now one thing I dont know is: When I want to load the cache, just like in the docs:

Code: Select all


ES3.CacheFile();
 
// Create an ES3Settings to load from cache.
var settings = new ES3Settings(ES3.Location.Cache);
 
// Load from the cached file.
var myInt = ES3.Load("myInt", 0, settings);
ES3.LoadInto("myTransform", this.transform, settings);

right? If I implement it like this in my SaveManager as a method and not in every script where I want to save and load something, would something like this be correct?

Code: Select all


public object LoadData(string loadKey, object defaultValue)
{
	ES3.CacheFile();
	var settings = new ES3Settings(ES3.Location.Cache);

	return ES3.Load(loadKey, defaultValue, settings);
}

And one more thing. When I equip an item for the first time I started the game I get a freeze for a couple of seconds. I checked it out with the Unity Profiler with Deep Profiling. Here is what I got:

Image

Image

Thank you once again
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: A lot of problems :/

Post by Joel »

Hi there,
What does ES3.CacheFile(); and ES3.StoreCachedFile(); without any parameters do?
It caches/stores the default file. In the same way that calling ES3.Save without the filePath parameter will store data to the default file.

Your LoadData example wouldn't provide any performance benefit because you're loading the entire file into the cache every time you load a single key. Instead the general workflow is to load the file into the cache (ES3.CacheFile()) once when the game first loads, and then call ES3.StoreCachedFile() after you have written a lot of keys to the file (for example when your player presses a Save button).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Paradox
Posts: 12
Joined: Wed Mar 29, 2023 11:59 am

Re: A lot of problems :/

Post by Paradox »

Hey,

thanks for the response. So if I use ES3.Save(); without a path string I can save via ES3.StoreCacheFile(); and load via ES3.CacheFile(); correct?
But when I use ES3.Save(); with a save path and try to use ES3.StoreCacheFile(); with the same path, it gives me an error saying the file path does not exist. Are these 2 paths different or do I need to set up the Cache with the path first?

Thanks as usual
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: A lot of problems :/

Post by Joel »

But when I use ES3.Save(); with a save path and try to use ES3.StoreCacheFile(); with the same path, it gives me an error saying the file path does not exist. Are these 2 paths different or do I need to set up the Cache with the path first?
Have you saved any data to that file in the cache or called ES3.CacheFile("file.es3") on that file beforehand? The file needs to exist in the cache for you to be able to call ES3.StoreCachedFile("file.es3") on it.

If so, please could you create a complete script which I can drop into a new scene of a new project which replicates your issue?
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Paradox
Posts: 12
Joined: Wed Mar 29, 2023 11:59 am

Re: A lot of problems :/

Post by Paradox »

Hi there,

its gonna be very hard to replicate this in only one script. Can I call ES3.FileExists(pathName) to check if a Cached File exists?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: A lot of problems :/

Post by Joel »

You would also need to provide an ES3Settings object with caching enabled. I.e.

ES3.FileExists(pathName, new ES3Settings(ES3.Location.Cache));

Otherwise it will be looking in the default save location, which is File.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Paradox
Posts: 12
Joined: Wed Mar 29, 2023 11:59 am

Re: A lot of problems :/

Post by Paradox »

I got it to work now. The results are so far amazing. It saves and loads so much faster. But I have a small problem. I have a List of a class called InputClass. I want the player to save their preferred input in the settings. So I save the Key Bindings but whenever I exit and reenter play mode I get this error coming from loading the List:

FormatException: Expected '{' or "null", found '['.

The class looks like this:

Code: Select all


[System.Serializable]
    public class InputClass
    {
        [ES3Serializable]
        public string name;
        [ES3Serializable]
        public bool showInKeybindingSettings = true;
        [ES3Serializable]
        public List<KeyCodeClass> keyCodeClassList = new();

        public InputClass()
        {

        }

        public InputClass(InputClass inputClass)
        {
            this.name = inputClass.name;
            inputClass.keyCodeClassList.ForEach(i => this.keyCodeClassList.Add(new(i.keyCode)));
            this.showInKeybindingSettings = inputClass.showInKeybindingSettings;
        }
    }

and the class responsible for saving has these key methods:

Code: Select all


        private void SaveInputs()
        {
            SaveManager.Instance.SaveDataOnDefault(GetInputListSaveID(), InputList);
        }

        private void LoadInputs()
        {
            InputList.Clear();
            InputList = (List<InputClass>)SaveManager.Instance.LoadDataOnDefault(GetInputListSaveID(), new List<InputClass>());
        }

        private string GetInputListSaveID() => "Input Save ID";
        
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: A lot of problems :/

Post by Joel »

This usually means the save data contains a List, but you're loading it as something other than a List. Please could you create a self-contained script which replicates this so I can see what is happening as the code you've posted doesn't allow me to replicate this.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Paradox
Posts: 12
Joined: Wed Mar 29, 2023 11:59 am

Re: A lot of problems :/

Post by Paradox »

Hi there,

I fixed this problem by updating Easy Save. Was probably fixed in a later version. But now I get an error every time I try to load any boolean:

Code: Select all

FormatException: String was not recognized as a valid Boolean.
I searched in the forum for this error but there was answer fixed it in my case. I have a test script:

Code: Select all


using System.Collections.Generic;

using UnityEngine;

public class EasySaveTest : MonoBehaviour
{
    [ES3Serializable]
    public bool boolean = false;

    private const string DEFAULT_PATH_STRING = "_defaultPath";

    private void Start()
    {
        Load();

        Invoke(nameof(TestSave), 0.1f);
    }

    public void Load()
    {
        var settings = new ES3Settings(ES3.Location.Cache);

        if (ES3.FileExists(DEFAULT_PATH_STRING, settings))
        {
            Debug.Log("Load Default Path Cache");
            ES3.CacheFile(DEFAULT_PATH_STRING, settings);
        }
    }

    public void Save()
    {
        // I call this method in my game every time I transition the scene
        var settings = new ES3Settings(ES3.Location.Cache);
        if (ES3.FileExists(DEFAULT_PATH_STRING, settings))
        {
            Debug.Log("Store Default Path Cache");
            ES3.StoreCachedFile(DEFAULT_PATH_STRING, settings);
        }
    }

    public void SaveDataOnDefault(string saveKey, object saveValue)
    {
        var settings = new ES3Settings(ES3.Location.Cache);

        if (saveValue != null)
        {
            Debug.Log("Save");
            ES3.Save(saveKey, saveValue, DEFAULT_PATH_STRING, settings);
        }
        else
        {
            Debug.Log("Delete");
            ES3.DeleteKey(saveKey, DEFAULT_PATH_STRING, settings);
        }
    }

    public object LoadDataOnDefault(string loadKey, object defaultValue)
    {
        var settings = new ES3Settings(ES3.Location.Cache);
        ES3.CacheFile(settings);

        return ES3.Load(loadKey, DEFAULT_PATH_STRING, defaultValue, settings);
    }

    private void TestSave()
    {
        SaveDataOnDefault(GetBoolID(), boolean);
        LoadDataOnDefault(GetBoolID(), null);

        Debug.Log(boolean);

        // I have Encryption enabled
    }

    private string GetBoolID() => "Bool Save ID";

}


Hopefully if I can get this to work I am finally done :lol:

Thanks as always!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: A lot of problems :/

Post by Joel »

Hi there,

I believe this issue is resolved in our next update. If you private message me your invoice number or order number I can send you an update which should resolve this.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply