Search Unity

Audio Multiple AudioMixer instanced from Addressables

Discussion in 'Audio & Video' started by hadesfury, Feb 27, 2020.

  1. hadesfury

    hadesfury

    Joined:
    Jan 23, 2014
    Posts:
    55
    Here is the problem,

    We defined a unique AudioMixer in our project with multiple groups.

    We are also using Addressables.

    The AudioMixer is instanced multiple time (up to 3, probably more) (when looking in the Audio Profiler).

    2020-02-27 12_08_08-Window.png

    The first hint I got was from https://forum.unity.com/threads/setfloat-broken-for-new-exposed-audio-mixer-parameters.828972/, we use to have that problem too.

    By putting the AudioMixer in an Addressable Group we reduced the "instance" count to 2, but it seems to continue to provoke sound bugs.

    Any know issues or workaround ?

    This bug occurs at least on :
    Unity 2018.4.15f1, 2018.4.17f1 with Addressables version is 1.6.2


    To give more information, we have multiple scenes, when the first scene is loaded, only one audiomixer is loaded, but after loading a second scene the second audiomixer is loaded.

    An interesting test I made was to bind the AudioMixer in object in each scenes. The one on the first scene looks normal
    correcly_bound_audio_mixer.png
    but the one in the second one does not seem to be right.
    incorectly_bound_audio_mixer.png

    _AudioMixerBug_.zip is a repro case for the bug here is the step :
    1. Open FirstScene.unity
    2. Build Addressable : Build>New Build>Default Build Script
    3. Open Profiler and select Audio, Detailed, Channels and groups, Reset play count on play
    4. Press start button, look that the audiomixer’s channels are loaded once
    5. Press any button on the green screen, it moves you to SecondScene, look that the audiomixer’s channels are loaded twice
     

    Attached Files:

    Last edited: Feb 27, 2020
    IggyZuk likes this.
  2. Fishing_Cactus

    Fishing_Cactus

    Joined:
    Nov 8, 2014
    Posts:
    45
    We were interested in this bug so we have tried your reproduction project on 2019.3.3 and we don't have this problem with this version.
     
  3. hadesfury

    hadesfury

    Joined:
    Jan 23, 2014
    Posts:
    55
    I also tested it on 2019.3.3f1 and at first I thought I didn’t have the bug, BUT the strange binding problem persist :( but that is true that in that repro, I don’t have the double mixer visually anymore.

    Thank you anyway
     
  4. hadesfury

    hadesfury

    Joined:
    Jan 23, 2014
    Posts:
    55
  5. Fishing_Cactus

    Fishing_Cactus

    Joined:
    Nov 8, 2014
    Posts:
    45
  6. IggyZuk

    IggyZuk

    Joined:
    Jan 17, 2015
    Posts:
    43
  7. akarpinski_unity

    akarpinski_unity

    Joined:
    Dec 27, 2017
    Posts:
    4
  8. Driiade

    Driiade

    Joined:
    Nov 21, 2017
    Posts:
    80
  9. Carocrazy132

    Carocrazy132

    Joined:
    Aug 16, 2015
    Posts:
    15
  10. Makkus

    Makkus

    Joined:
    Sep 14, 2015
    Posts:
    20
    I experience the same problem (Unity 2019.4.30f, Win10), I've got two AudioMixers instantiated. In the first scene there is only one mixer, on the second I get two. Interestingly, all audio is routed through the mixer that can not be edited via "Edit in Play Mode" button. Additionally most content (including AudioSources) reside in AssetBundles in my case. I wonder how the AudioMixer is instantiated internally? To me it looks like one mixer is loaded as a dependency from the asset bundle but the other one is somehow loaded by default (maybe with the AudioListener?).
    Any idea how to work around this problem?
     
  11. kcaglarguler

    kcaglarguler

    Joined:
    Aug 10, 2021
    Posts:
    1
    +1, I'm having this issue on build. In Editor, it works correctly, I have only one Mixer instance. But in Build, there is two and it causes some problems like, if I change a parameter in mixer, the other copy mixer is not affected by the change of that. (We are using IL2CPP for build.)
     
    Last edited: Dec 22, 2021
    ttesla likes this.
  12. afftar

    afftar

    Joined:
    Apr 18, 2014
    Posts:
    65
    I also ran into this problem. It looks like we need some kind of GLOBAL mixer for the block, which will always and will not depend on Addressable. Otherwise, this whole system with mixers becomes absolutely useless in conjunction with Addressable.
    The saddest thing is that I spent a huge amount of time searching for the bug myself, at a time when it was a known problem. Such problems should be explicitly documented, otherwise you are just mocking your developers. This is absolutely not a clear violation of the logic of the workflow.
     
    AntonPetrov likes this.
  13. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    612
    This was a pain to fix and after spending some time here's the easiest "fix".

    Note, we didn't want to make our scenes addressables as this would have changed the workflow for our entire project.
    Our project uses Addressables for levels and enemies, but the scenes, ui, etc are not addressables.

    1) Create a singleton to store your audio mixer.
    2) In the singleton, you can either load the AudioMixer as an addressable or choose to use the scene reference.

    3) Choose one of the following:

    If you choose to use Addressables (i.e. AssetReference), then you should add a component to every scene AudioSource to set the mixer group at runtime.

    If you choose to use the scene reference audio mixer, then you should add a component to every Addressable prefab that has an audio source to set the mixer group at runtime.

    Code (CSharp):
    1.   public class MixerSingleton : MonoBehaviour
    2.     {
    3.         public static MixerSingleton Instance;
    4.  
    5.         [SerializeField]
    6.         private AssetReference _mixerAddressable;
    7.  
    8.         [SerializeField] private AudioMixer _sceneMixer;
    9.  
    10.         public AudioMixer Mixer { get; private set; }
    11.  
    12.         public void Awake()
    13.         {
    14.             if (Instance == null)
    15.             {
    16.                 Instance = this;
    17.             } else if (Instance != this)
    18.             {
    19.                 Destroy(this);
    20.                 return;
    21.             }
    22.             DontDestroyOnLoad(this);
    23.            
    24.             // Choose one
    25.             SetupSceneMixer();
    26.             // SetupAddressablesMixer();
    27.         }
    28.  
    29.         private void SetupAddressablesMixer()
    30.         {
    31.             Addressables.LoadAssetAsync<AudioMixer>(_mixerLoader).Completed += OnCompleted;
    32.         }
    33.  
    34.         private void SetupSceneMixer()
    35.         {
    36.             Mixer = _sceneMixer;
    37.         }
    38.  
    39.         private void OnCompleted(AsyncOperationHandle<AudioMixer> obj)
    40.         {
    41.             Mixer = obj.Result;
    42.         }
    43.     }
    We went with using the scene reference to the AudioMixer as there was many more AudioSource in scenes to set the group for then there were Addressables. So the idea is to update the addressable AudioSource mixer group to the group from the scene reference at runtime.