Forum rules - please read before posting.

Prevent slider from saving PlayerPrefs Key continuously?

Im using the SaveFileHandler_PlayerPrefs to save settings and savegames, and noticed that when adjusting the volumes in the options menu the AC debug logger shows that the playerprefs key is being continuously saved when the slider is moving. Preferably the playerprefs should only be saved when either the slider is released, or when the player presses the back button.

What way would be the best way to prevent this behaviour?

On latest AC and Unity 2018.3.7f1

This is the log:
PlayerPrefs Key 'AC_milkmaid_0' saved

-> AC debug logger
UnityEngine.Debug:Log(Object, Object)
AC.ACDebug:Log(Object, Object) (at Assets/AdventureCreator/Scripts/Static/ACDebug.cs:16)
AC.OptionsFileHandler_PlayerPrefs:SaveOptions(Int32, String, Boolean) (at Assets/AdventureCreator/Scripts/Options/OptionsFileHandler_PlayerPrefs.cs:24)
AC.Options:SavePrefsToID(Int32, OptionsData, Boolean) (at Assets/AdventureCreator/Scripts/Options/Options.cs:124)
AC.Options:SavePrefs(Boolean) (at Assets/AdventureCreator/Scripts/Options/Options.cs:100)
AC.Options:SetVolume(SoundType, Single) (at Assets/AdventureCreator/Scripts/Options/Options.cs:707)
AC.MenuSlider:UpdateValue() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSlider.cs:501)
AC.MenuSlider:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSlider.cs:620)
AC.MenuElement:ProcessClickUI(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:250)
AC.c__AnonStorey0:<>m__0(Single) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSlider.cs:152)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
Rewired.Integration.UnityUI.RewiredPointerInputModule:ProcessDrag(PlayerPointerEventData) (at Assets/Rewired/Integration/UnityUI/RewiredPointerInputModule.cs:493)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:ProcessMouseEvent(Int32, Int32) (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:968)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:ProcessMouseEvents() (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:950)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:Process() (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:652)


  • If you link the Slider to a "Float" Global Variable, you can match the variable's value to the correct volume when the menu turns on, and then match the volume to the variable's value when the menu turns off.

    Using the music volume as a test, create a new float variable called "TempMusic" and record the ID number. Change your MusicVolume slider's Slider affects field to Float Variable and select "TempMusic" from the drop-down.

    The following script, with the correct ID number set in it's Inspector, should then map the variable to the volume:

    using UnityEngine;
    using System.Collections;
    using AC;
    public class MusicVariableExample : MonoBehaviour
        public int musicVariableID;
        private void OnEnable ()
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnMenuTurnOff += OnMenuTurnOff;
        private void OnDisable ()
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnMenuTurnOff -= OnMenuTurnOff;
        private void OnMenuTurnOn (Menu menu, bool isInstant)
            if (menu.title == "Options")
                GlobalVariables.SetFloatValue (musicVariableID, Options.GetMusicVolume ());
        private void OnMenuTurnOff (Menu menu, bool isInstant)
            if (menu.title == "Options")
                Options.SetMusicVolume (GlobalVariables.GetFloatValue (musicVariableID));
  • Thanks for this, this looks like a viable way to make this work.
    I ended up mapping a PlayerPrefs.Save(); function to the back button, which does the actual save file writing on the platform I'm targeting. It appears AC doesn't save automatically to this platform with my current setup - I have to manually trigger the playerprefs to save, and this seems to work in my favour this time :smile:

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.