Exception: Key "SaveBasic" was not found in this ES3File

Discussion and help for Easy Save 3
Post Reply
tzwyf
Posts: 6
Joined: Mon Nov 08, 2021 8:36 am

Exception: Key "SaveBasic" was not found in this ES3File

Post by tzwyf »

Hello!

Recently, my game is onlion with the EasySave3. I save game data by Cache and StoreCachedFile, but some users meet the problem as the subject when they load game data, and they are always loading on the start scene.(This appears to be the case with only some mobile phones)

Next is my function code.

Code: Select all

	public const string GAME_PATH = "GameSaved.es3";
	
	public void SaveGameBasic()
        {
                var settings = new ES3Settings(Config.GAME_PATH, ES3.Location.Cache);
                saveBasic.UpdateSaveBasic();
                ES3.Save("SaveBasic", saveBasic, settings);
                ES3.StoreCachedFile(Config.GAME_PATH);
            
        }
        public void SaveGameByES3(bool saveRT = false)
        {
            var settings = new ES3Settings(Config.GAME_PATH, ES3.Location.Cache);

            SaveGameBasic();

            if (saveRT)
            {
                for (int i = 0; i < DataManager.Instance.randomThingsList.Count; i++)
                {
                    var rt = DataManager.Instance.randomThingsList[i];

                    SaveRT(rt);
                }
            }

            ES3.Save("SaveCourse", DataManager.Instance.courses, settings);
            ES3.Save("SavePeople", DataManager.Instance.peopleList, settings);
            ES3.Save("SaveProduct", DataManager.Instance.productList, settings);
            ES3.Save("SaveMagic", DataManager.Instance.allMagicList, settings);
            ES3.Save("SaveBuilding", DataManager.Instance.buildingList, settings);

            ES3.StoreCachedFile(Config.GAME_PATH);
            PlayerPrefs.SetInt(Config.GAME_SAVE_KAY, 1);
        }
        public void LoadGameByES3()
        {
            ES3.CacheFile(Config.GAME_PATH);
            var settings = new ES3Settings(Config.GAME_PATH, ES3.Location.Cache);

            saveBasic = ES3.Load<SaveBasicSO>("SaveBasic", settings);
            if (saveBasic != null)
            {
                saveBasic.LoadData();
            }

            DataManager.Instance.courses = ES3.Load<List<CourseSO>>("SaveCourse", settings);
            DataManager.Instance.randomThingsList = LoadRTList(DataManager.Instance.rtKeyList, settings);
            DataManager.Instance.peopleList = ES3.Load<List<PeopleSO>>("SavePeople", settings);
            DataManager.Instance.productList = ES3.Load<List<ProductSO>>("SaveProduct", settings);
            DataManager.Instance.allMagicList = ES3.Load<List<MagicSO>>("SaveMagic", settings);
            DataManager.Instance.buildingList = ES3.Load<List<BuildingSO>>("SaveBuilding", settings);
        }
SaveGameBasic only save some basic data and is always called.SaveGameByES3 is called when some options are done on otehr SOs.
I also call SaveGameByES3 when unity function "OnApplicationPause" works on true.
when users start game, they will call the LoadGameByES3 function if Config.GAME_SAVE_KAY == 1, and some users meet the detail problem as next.

Code: Select all

Key "SaveBasic" was not found in this ES3File. Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.
So, i hope for your advice!
Last edited by tzwyf on Mon Nov 08, 2021 9:34 am, edited 1 time in total.
tzwyf
Posts: 6
Joined: Mon Nov 08, 2021 8:36 am

Re: Exception: Key "SaveBasic" was not found in this ES3File

Post by tzwyf »

Unity version: 2020.3.9f1c1
bug phone modle: Xiaomi mix4, onePlus7 pro, and some HuaWei phone(tel-an10,Mate40,mate30 Pro) maybe HarmonyOS system
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Exception: Key "SaveBasic" was not found in this ES3File

Post by Joel »

Hi there,

We've had no other reports of this.

If Easy Save encounters an issue when creating a file then it will throw an IO exception. As you don't appear to be getting this, this indicates that either the code to save the data isn't being called (which would be an issue with your logic or Unity), there is an issue with the device or OS, or the user has removed the file themselves.

I'd also recommend ensuring that you're using the latest version of Easy Save, if you're not already.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
tzwyf
Posts: 6
Joined: Mon Nov 08, 2021 8:36 am

Re: Exception: Key "SaveBasic" was not found in this ES3File

Post by tzwyf »

OK,thanks for your advice.
tzwyf
Posts: 6
Joined: Mon Nov 08, 2021 8:36 am

Re: Exception: Key "SaveBasic" was not found in this ES3File

Post by tzwyf »

After a few days of testing, this problem is most likely caused by that I save game data in OnApplicationPause(true).If user quit game fast so that the data file is saving on .es3.tmp format and to late to be saved by .es3 format. When users load game next time, they will not find the key in .es3.tmp file.

So far,no users feedback the problem of stuck in loading scene after I remove the save code in OnApplicationPause(true).
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Exception: Key "SaveBasic" was not found in this ES3File

Post by Joel »

Hi there,

Thanks for the info. If you’re able to replicate this then I recommend reporting it to Unity, as OnApplicationPause should block until execution is complete. If certain devices are stopping execution early then this is something Unity would want to be aware of.

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