Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug AudioMixer sub-groups volume on Android

Discussion in 'Audio & Video' started by lordofduct, Oct 27, 2022.

  1. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,384
    I have an AudioMixer setup with groups like this:
    upload_2022-10-27_16-57-57.png

    Everything in my game is configured to be under one of the 3 subgroups BGM/SFX/Ambience.

    I have the parameters for the volume exposed:
    upload_2022-10-27_16-58-46.png

    And this is the logic I use to set the volume:
    Code (csharp):
    1.         public static bool SetVolume01(this AudioMixer mixer, string name, float value)
    2.         {
    3.             if (value < 0.0001f)
    4.             {
    5.                 value = -80f;
    6.             }
    7.             else
    8.             {
    9.                 value = Mathf.Log10(Mathf.Clamp01(value)) * 20f;
    10.             }
    11.  
    12.             return mixer.SetFloat(name, value);
    13.         }
    Called like so:
    Code (csharp):
    1.         public const string LABEL_AMBIENT = "AmbienceVolume";
    2.  
    3.         private void _ambientVolumeWidget_Clicked(object sender, System.EventArgs e)
    4.         {
    5.             if (!_ambientVolumeWidget) return;
    6.  
    7.             var audio = Services.Get<IAudioManager>();
    8.             if (audio != null)
    9.             {
    10.                 audio.SetVolume(LABEL_AMBIENT, _ambientVolumeWidget.SelectedIndex / 10f);
    11.             }
    12.             PlayerPrefs.SetInt(PREF_AMBIENT, _ambientVolumeWidget.SelectedIndex);
    13.         }
    Yes, I know it's technically the type IAudioManager, that method just passes through to the audiomixer in question. Like so:
    Code (csharp):
    1.         public bool SetVolume(string label, float value)
    2.         {
    3.             return _audioMixer.SetVolume01(label, value);
    4.         }
    When I run this in editor all works just fine and I can mute any the 3 groups by setting the volume to 0.

    But when I run this on Android device directly, it doesn't work.

    I've attached the debugger and stepped through the code. The logic gets called, the correct label is passed into the audiomixer and the correct db -80 when the volume is 0. No exceptions thrown, nothing. But it behaves like it's at full volume.

    Anyone have any ideas?

    I've labeled as bug as I am left only thinking this is a Unity issue... unless I'm a complete dolt and missing something. Maybe the volume isn't in db on Android???
     
    Last edited: Oct 27, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    Duct! Good to see you making a top level post.

    All I can suggest is to isolate, isolate, isolate.

    First I'd make a new scene and a trio of buttons to set 0, 0.5f, 1.0 as inputs... as little code as possible... ideally one monobehaviour with one button service call.

    And if THAT doesn't work, make a new project and retry it there.

    If you do that and it fails when absolutely nothing else in your game is running, then yeah, we can call it a bug.

    (or maybe we don't understand the API / arguments? I'm always open to that possibility...)
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,384
    I figured out what it is...

    Ugh.... oh dear god ugh.

    It's because the prefabs I'm loading are all addressables. And their AudioSources are configured to the AudioMixer in the project. But when the addressables are compiled a COPY of the AudioMixer is put into the package for those addressables.

    Where as my IAudioManager is pointed at the AudioMixer embedded in the game itself.

    So technically on load on device, 2 AudioMixers are getting loaded. Where as in editor it emulates the remote addressables by reading from the local assets folder.

    I actually ran into this with my "proxy" library (scriptable objects that allow simple remote signaling between objects... sort of similar to your/@Kurt-Dekker data sacks in some ways, but not fully). I had to hack a way to deal with it there to recognize that proxies with the same uid should be considered the same regardless of source.

    ...

    I'm going to have to do something about this for AudioMixer now... no idea HOW, but yeah, that's what I'm going to have to do.

    ...

    I don't know if I'd consider this a bug or not though... it's less a bug and just a result of how addressables work. But it's not very intuitive though.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    It's more Addressables with widely-shared ScriptableObjects basically.

    We ran slamming into this because we had an ApplicationContext high level ScriptableObject that just about every object in the game used to communicate.

    Pulled one level out to make it an addressable... and helpfully Unity makes a copy of our ApplicationContext, because just about everything from Animators to ZebraCrossings reference it.

    Now you can see what happens when we loaded that Addressable level. :/ I'll have to dig a bit and report on what we ultimately did... it was quite a few projects back now.
     
  5. Vintecus

    Vintecus

    Joined:
    May 28, 2021
    Posts:
    1
    Seems to still be an ongoing issue as my audioMixer works in editor as well but not on android build. The work around I used was to link my sliders to the audiosources individually on my audiomanager class. The on value changed of the slider would update the audiosource volume sliders. Hope this helps
     
  6. JosephStar318

    JosephStar318

    Joined:
    Jun 20, 2022
    Posts:
    15
    I do not use asset bundles. I can setfloat the master volume and it works fine in both editor and mobile but when i setfloat the subgroups it doesn't work on mobile. As a work around i don't want to set multiple mixers either. does anyone know what might be issue here?
    Note: Unity version 2022.3.5f1