- Home /
AudioMixer and Awake
I have encountered a courious behaviour with the AudioMixer. I want to change the Volumes of my Sounds on startup to match the ones saved the last time the game was running, so I put a function in an Awake() to read a float from PlayerPrefs and use that in the AudioMixer. But this does not work. There is no exception thrown, but AudioMixer.SetFloat() doesn't seem to have an effect in Awake(). The same code works fine in Start().
Is this a desired or anticipated behaviour, and I just don't see the reason or explanation?
(Side Note: AudioMixer.GetFloat() does work in Awake(), but it returns the value set vie the Audio Mixer tab in the Editor)
Is there a reason why you don't want to do that in the Start() function ??
I always do it in Start() when i try to do stuff like that on Awake i also get strange results so is not even an option for me .Just to add to this, having the same issue. $$anonymous$$ade a test script to reassign the floats on a button press, and it works once the scene is initialized, nothing else works on Awake.
Same problem here. It seems that the SetFloat is not ready to be used, although unity don't even show a error or warning message at the console.
Same Here: SetFloat doesn't work in Awake, but works in Start. Sounds like a bug to me.
Answer by Rabadash8820 · Jan 12, 2020 at 06:05 AM
I know its like 5 years later, but I was just grappling with this issue myself in 2019.2. Looks like, oddly enough, this is intended behavior. I.e., getting AudioMixer parameters in Awake
is fine, but setting them is undefined behavior.
Thanks for posting that. 5 years later they still haven't fixed their documentation so we still have to rely on a bug report from a rather unknown unity subdomain to let us know that this is undocumented, confusing, but "intended" behavior by the developers, who haven't seen fit to officially enlighten us on the SetFloat() page... I wasted 5 hours trying to debug this before finally finding the right combination of google keywords to search and come up with this post!