Question about mobile build and Easy Save

Discussion and help for Easy Save 3
Post Reply
theUnsigned
Posts: 5
Joined: Wed Jun 07, 2023 5:35 pm

Question about mobile build and Easy Save

Post by theUnsigned »

Good day,

I have been using Easy Save to great effect since I purchased it, thank you so much for this great asset.

I have a script that works well in the editor but does not work in my mobile build and, after a few days of troubleshooting and researching, I would like to ask for some assistance to fix it and to better understand how to use Easy Save.

This code is supposed to sync the user's saved volume setting onenable, onfocus(true), and onpause(false). I've tried different combinations of these calls but I can't get it to work correctly on build, though it works in the editor. It is also intended to change the value of the UI Toolkit slider to math the saved volume float, which works fine in the editor between plays (I understand this is not the same as closing an application):

Code: Select all

void SyncVolume ()
    {
        
        if (ES3.KeyExists("Music"))
        {
            sl_music.value = ES3.Load<float>("Music");
            SoundVolumeChange(sl_music.value, "Music");

        }

        if (ES3.KeyExists("SFX"))
        {
            sl_sfx.value = ES3.Load<float>("SFX");
            SoundVolumeChange(sl_sfx.value, "SFX");
        }

    }
    void SoundVolumeChange (float volume, string type)
    {
        
        audioMixer.SetFloat(type, MathF.Log10( volume)*20);
        ES3.Save<float>(type, volume);

    }
Any assistance would be greatly appreciated since I need to sync other saved values and could benefit from better understanding Easy Save. Thank you kindly.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Question about mobile build and Easy Save

Post by Joel »

Hi there,

Firstly I recommend putting Debug.Log calls next to your Load code to ensure that it's getting called. If it's not getting called then that would indicate an issue with Unity's events rather than at our end.

Also have you accounted for the situation where no save data will exist when the app is first installed? It may be that your Editor build has save data already but your mobile build does not. To replicate this in the Editor you can delete your save data by going to Tools > Easy Save 3 > Clear Persistent Data Path.

Also I think you may have misspoken, but it doesn't make sense to load in OnApplicationPause/Focus, but perhaps you mean that you're saving at these points rather than loading. Generally you would save data when the app loses focus, and load data when the app first loads.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
theUnsigned
Posts: 5
Joined: Wed Jun 07, 2023 5:35 pm

Re: Question about mobile build and Easy Save

Post by theUnsigned »

Thank you, I'm not sure if I misspoke or simply described my flawed and circular logic. I got it working with your guidance, here's the working code, I call SyncVolume OnEnable, OnApplicationFocus(false), and OnApplicationPause(true) and have registered callback events for the sliders to link to SoundVolumeChange():

Code: Select all

void SyncVolume ()
    {
        
        if (ES3.KeyExists("Music"))
        {
            sl_music.value = ES3.Load<float>("Music");
            //Debug.Log($"synced volume on syncvolume Music - key exists - {ES3.Load<float>("Music")}");
        }
        else
        {
            SoundVolumeChange(sl_music.value, "Music");
            //Debug.Log($"synced volume on syncvolume Music - key does not exist - {ES3.Load<float>("Music")}");
        }
        if (ES3.KeyExists("SFX"))
        {
            sl_sfx.value = ES3.Load<float>("SFX");
        }
        else
        {
            SoundVolumeChange(sl_sfx.value, "SFX");
        }
    }
    void SoundVolumeChange (float volume, string type)
    {
        
        audioMixer.SetFloat(type, MathF.Log10( volume)*20);
        ES3.Save<float>(type, volume);
        //Debug.Log($"synced volume on SoundVolumeChange Music - {ES3.Load<float>("Music")}");

    }
Thank you so much, I
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Question about mobile build and Easy Save

Post by Joel »

Glad that's all working for you now :)

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