Easy Save works on Unity Editor, but not on Android.

Discussion and help for Easy Save 3
Post Reply
Oohara
Posts: 2
Joined: Sat Dec 24, 2022 5:30 am

Easy Save works on Unity Editor, but not on Android.

Post by Oohara »

Hello.
In my project, the SaveData class save and load works on Unity Editor, but not on Android (not tested on iOS), and I am having problems with corrupted save data or missing (not saved?) save data.

The save data is saved in SaveData class, which contains the custom classes skill_data, WorldData, and Owned_skill. Of these, skill_data and WorldData are ScriptableObjects.

Code: Select all

using System.Collections.Generic;
[System.Serializable]
public class SaveData
{
    public int jewel;
    public int enemies_defeated;

    public bool got_first_weapon;
    public bool playing_now;
    public bool FirstSettingDone;
    public bool CanRevive;

    public int enemies_defeated;

    public skill_data first_equipped_skill;
    public WorldData current_world;

    public List<Owned_skill> saved_skill;
    public List<skill_data> registered_list;

    public static readonly int Upgrades = 4;
    public int[] Player_UpgradeLv = new int[Upgrades];

    public int RerollLeft;

    public int LV;
    public float CurrentExp;

    public float BGMVolume, SEVolume;

    public static readonly int Descriptions = 2;
    public bool[] DescriptionDone = new bool[Descriptions];

    public bool CanAccessGachaAndUpgrade;

    public SaveData()
    {

    }

    public SaveData(SaveData Copydata)
    {
        jewel = Copydata.jewel;
        playing_now = Copydata.playing_now;
        FirstSettingDone = Copydata.FirstSettingDone;
        CanRevive = Copydata.CanRevive;
        got_first_weapon = Copydata.got_first_weapon;
        enemies_defeated = Copydata.enemies_defeated;

        first_equipped_skill = Copydata.first_equipped_skill;
        current_world = Copydata.current_world;

        saved_skill = new List<Owned_skill>(Copydata.saved_skill);
        registered_list = new List<skill_data>(Copydata.registered_list);

        BGMVolume = Copydata.BGMVolume;
        SEVolume = Copydata.SEVolume;

        for (int i = 0; i < Copydata.Player_UpgradeLv.Length; i++)
        {
            Player_UpgradeLv[i] = Copydata.Player_UpgradeLv[i];
        }
        for (int i = 0; i < Copydata.DescriptionDone.Length; i++)
        {
            DescriptionDone[i] = Copydata.DescriptionDone[i];
        }

        RerollLeft = Copydata.RerollLeft;

        LV= Copydata.LV;
        CurrentExp = Copydata.CurrentExp;

        CanAccessGachaAndUpgrade = Copydata.CanAccessGachaAndUpgrade;
    }
}
In addition, one Easy Save 3 Manager was placed in each scene, and all ScriptableObjects were Add Refference(s) to Manager. Saving and loading the save data is done as follows with singleton objects.

Code: Select all

    private void Awake()
    {
        DataLoad();
    }

    public void DataSave()
    {
        ES3.Save("RunGame", saved_data);
    }

    public void DataLoad()
    {
        if (ES3.KeyExists("RunGame"))
        {
            SaveData LoadData =
                (SaveData)ES3.Load("RunGame");
            saved_data = new SaveData(LoadData);
        }
    }

    private void OnApplicationQuit()
    {
        DataSave();
    }

    private void OnApplicationPause(bool pauseStatus)
    {
        if (pauseStatus)
            DataSave();
    }
There are two things I found.
The first is that when the save data is corrupted, the primitive data types such as jewel and Player_UpgradeLv are saved normally and the loading problem occurs only in the custom classes.
The second is that on Android, when you return to the home screen to close the game, the game is not saved immediately, but you have to wait for a while. You have to wait for a while. If you close the game quickly, the game does not save.

Thanks in advance.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save works on Unity Editor, but not on Android.

Post by Joel »

Hi there, and thanks for getting in contact.

Please could you add a Debug.Log call to the beginning and end of your DataSave and DataLoad methods so that you can see when they’re being called.

Could you then delete your app from your device, reinstall it and then replicate your issue, and send me the console log. This should help us understand what is happening.
The second is that on Android, when you return to the home screen to close the game, the game is not saved immediately, but you have to wait for a while. You have to wait for a while. If you close the game quickly, the game does not save.
This would indicate an issue with Unity’s OnApplicationPause event not providing enough time for the code to be executed. In this case you would either need to contact Unity for a resolution (as unfortunately we have no control over their events), or save at a different point.

All the best,
Joel

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Oohara
Posts: 2
Joined: Sat Dec 24, 2022 5:30 am

Re: Easy Save works on Unity Editor, but not on Android.

Post by Oohara »

I rewrote the singleton object code as follows(They are tagged for visibility in the Unity Editor)

Code: Select all

    private void Awake()
    {
        DataLoad();
    }

    public void DataSave()
    {
	Debug.Log("<color=cyan>TRYING to SAVE</color>");
        ES3.Save("RunGame", saved_data);
	Debug.Log("<color=cyan>DATA SAVED!</color>");
    }

    public void DataLoad()
    {
        if (ES3.KeyExists("RunGame"))
        {
	    Debug.Log("<color=cyan>TRYING to LOAD</color>");
            SaveData LoadData =
                (SaveData)ES3.Load("RunGame");
            saved_data = new SaveData(LoadData);
	    Debug.Log("<color=cyan>DATA LOADED!</color>");
        }
    }

    private void OnApplicationQuit()
    {
        DataSave();
    }

    private void OnApplicationPause(bool pauseStatus)
    {
        if (pauseStatus)
            DataSave();
    }
Next, I rebuilt it to Android. However, since the previous data remained, I also deleted the storage.

When I observed the log with Android Device Monitor, this warning was displayed on the second and subsequent DataLoad.

Code: Select all

12-28 21:05:58.352: I/Unity(20871): <color=cyan>TRYING to LOAD</color>
12-28 21:05:58.666: W/Unity(20871): Reference for skill_data with ID 685581362839691099 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.666: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.673: W/Unity(20871): Reference for skill_data with ID 6674979481735316334 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.673: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.674: W/Unity(20871): Reference for skill_data with ID 685581362839691099 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.674: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.675: W/Unity(20871): Reference for skill_data with ID 7793303264076511511 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.675: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.675: W/Unity(20871): Reference for skill_data with ID 8312802570571902642 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.675: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.675: W/Unity(20871): Reference for skill_data with ID 1747590677868887839 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.675: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.675: W/Unity(20871): Reference for skill_data with ID 8522470056569081093 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
12-28 21:05:58.675: W/Unity(20871): <i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
12-28 21:05:58.690: I/Unity(20871): <color=cyan>DATA LOADED!</color>
DataSave did not show any warnings, but there was a several seconds lag before the DATA SAVED!
DataLoad was still broken whether I quitted after the DATA SAVED!
As for DataSave, I will give up on saving at the end of the game and consider doing it at another time.

Code: Select all

12-28 21:14:26.453: I/Unity(22097): <color=cyan>TRYING to SAVE</color>
12-28 21:14:26.472: I/Unity(22097): <color=cyan>DATA SAVED!</color>
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Easy Save works on Unity Editor, but not on Android.

Post by Joel »

Hi there,

Unfortunately it’s not possible to tell what is happening from what you’ve sent. Please could you replicate your issue in a new project with a simple scene and private message it to me with instructions so I can see what is happening.

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