Hi,
I have a slider in my Pause menu that controls the music volume in an Audio Mixer. I want that slider to be controlled by a PlayerPref to remember the volume between sessions.
Anyways, in a script I wrote slider.value = PlayerPref.GetInt… and it works just fine, it adjusts the audio, but the problem is the timing isn’t right.
If I put it in the Start() area then it’s too late - I hear the music loudly for a millisecond before it’s turned down to the PlayerPref value.
But if I put it in the Awake() area it’s too early - and it will change the position of the slider but not the volume of the music - I’m guessing that’s because the script is being executed before the Audio Mixer is instructed what the slider should be changing. If I drag the slider after that it still works fine and changes the music, but that first adjustment from the Awake() area only visually changes the slider, and music is the default volume. If I restart the game from within the game, using a restart button I made, then the audio will be correctly adjusted from PlayerPref from the Awake area the second time I play, and after.
So to summarize, if I control the slider from Awake() it’s too early and the slider visually changes, but the audio mixer isn’t affected. If I control the slider from Start() it’s too late, and I hear the music loudly for a millisecond before the music volume goes down to the PlayerPref value. I’ve tried it on a script attached to the slider object as well as a different object.