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.

Resolved Audio Mixer in addressable assets

Discussion in 'Addressables' started by IggyZuk, Nov 22, 2020.

  1. IggyZuk

    IggyZuk

    Joined:
    Jan 17, 2015
    Posts:
    42
    Is there a proper solution when it comes to serializing audio mixers in addressable assets?

    I have one audio mixer that is used for addressable assets and non-addressable assets. I would like to set the volume/mute all of the sounds, but it seems to only affect the non-addressable assets. It almost looks like addressable assets reference a clone of the audio mixer.

    We have the original mixer:

    Screenshot 2020-11-22 at 12.56.50 pm.png

    We add the sound group to an audio source of an addressable asset:

    Screenshot 2020-11-22 at 12.57.11 pm.png

    If we play and use existing addressable assets, the master mixer shows this:

    Screenshot 2020-11-22 at 12.57.21 pm.png

    Audio profiler also suggests that there are now two identical mixers:

    Screenshot 2020-11-22 at 1.10.04 pm.png

    I've found a related forum post, but those solutions are a little whacky.
     
    Last edited: Nov 22, 2020
  2. ruiyl

    ruiyl

    Joined:
    Aug 4, 2019
    Posts:
    20
    I also have the same problem. Seems like the Audio Mixer referenced in the addressable assets are the different one from the one referenced by the non-addressable assets. I did a hacky fix by:

    Code (CSharp):
    1. aaAudioSource.outputAudioMixerGroup = nonAAAudioSource.outputAudioMixerGroup;
    Make them use the same Audio Mixer
     
    MarcBaques likes this.
  3. akarpinski_unity

    akarpinski_unity

    Joined:
    Dec 27, 2017
    Posts:
    4
    Same problem here.
     
  4. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,698
    I'll raise this with the team for a bit of guidance.
     
  5. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,188
    Yeah this is a problem with how Addressables deal with ScriptableObject duplication.
    If you run the analyzer tool, you should notice the mixer displayed as a "non fixable" scene duplication issue.
    Which means, Unity will duplicate the mixer for addressable assets and use the original for scene assets.

    Solution...

    1. Don't reference the Mixer in addressable assets. Instead, use a static Singleton which Addressable assets can query to get the mixer.
    2. Don't reference the Mixer in scenes. Always load the mixer through Addressable assets
    3. Make all scenes addressable

    https://forum.unity.com/threads/scriptableobject-asset-and-addressables.652525/
     
    FuriousEX likes this.
  6. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    205
    CDF is correct, you will be duplicating the Objects. Addressables and the Player builds do not know of any content between each build.
    Marking all Scenes are Addressables as with CDF's point 3, will be the easiest way to keep your content in sync. Then have a bootup scene that loads your initial Scenes using Addressables, with them from local Addressable groups.

    One thing to note is that the AudioSource has a reference to the Mixer. If the Mixer is not marked as Addressable. Then it will be included with the AudioSource as an implicitly included Asset (As everything in Addressables must be included). This can lead to lots of duplicated Mixers for each implicitly included AudioMixer from AudioSource reference. To stop this duplication across different Addressable Groups/Packs also, the Mixer should be included in Addressables.
     
    FuriousEX and IggyZuk like this.
  7. IggyZuk

    IggyZuk

    Joined:
    Jan 17, 2015
    Posts:
    42
    @andymilsom Ah well that makes sense, thanks for the details.
    I've tried it in my current project and it does work. :cool:
     
  8. FuriousEX

    FuriousEX

    Joined:
    Mar 13, 2014
    Posts:
    38
    So this implies the Play On Awake feature of AudioSource just cannot be used with Addressables since the Output mixer group must be set via script - right?

    Not a fan of these core workflow workarounds.
     
  9. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    205
    You don't necessarily need to set via script. It is just to avoid multiple copies of the mixer why you do above.

    If you have Player Scenes and Addressables content referencing the same audio mixer, you may have the following:

    Player:
    SceneList
    - Scene 1 -> AudioMixer (1)

    Addressables
    SceneGroup1
    - Scene 2 -> AudioMixer (2)
    Other content,
    - MixerManipulationScript -> AudioMixer (3)

    Where in the Editor each part above references the same AudioMixer. At runtime they will be separate copies of the same AudioMixer. So if say "Other content" was a script that edits the AudioMixer and expect (1) and (2) to be affected, will not actually change the mixers (1) and (2).

    This happens because Player content and Addressables content do not know about each other. In Addressables when you build each bundle, if there are any references to Assets that are not explicitly assigned to Addressables then it will be included as a copy.
    Because of this, we recommend you A, use Addressables instead of the Player Scene list and set them as local. B use the Analyze rule to detect duplicate dependencies and set any you do not want as duplicated to an Addressables group.
    Resulting in like the following, where the Scenes are in Addressables and AudioMixer is assigned to "Other content" group.

    Player:
    - Bootup scene only used to setup

    Addressables
    SceneGroup1
    - Scene 1 -> Reference to "Other content: AudioMixer"
    SceneGroup2
    - Scene 2 -> Reference to "Other content: AudioMixer"
    Other content,
    - MixerManipulationScript
    - AudioMixer

    Now when the "Other content" edits the AudioMixer, it will be the AudioMixer that is used elsewhere instead of copies.
     
  10. FuriousEX

    FuriousEX

    Joined:
    Mar 13, 2014
    Posts:
    38
    Sure but realistically duplicate mixers are not shippable in a quality game - user facing audio level options are a basic requirement, meaning option scripts need fixed references to the mixers.

    The core workflow is: object's prefab sound references mixer A via inspector. Mixer A exists in scene. Spawn object. Audio plays on awake using mixer reference.

    When that object is an addressable that is loaded and spawned the core workflow is broken, right? A copy of the mixer is created and the options script will have no reference to it. Something must reset the mixer reference, right?
     
  11. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    205
    Only when the Mixer is not marked as Addressables (AFAIK AudioMixer is an Asset and does not exist in a Scene). So long as the Mixer is in Addressables, and the Content that references the Mixer is in Addressables. Then all of the content will reference the same Mixer object.
     
  12. FuriousEX

    FuriousEX

    Joined:
    Mar 13, 2014
    Posts:
    38
    I had an AudioMixer flagged as addressable but it is loaded via a reference in my launcher scene - this led to Mixer duplication. Does that mean the Mixer has to be loaded by addressables for the addressable references to work the way you describe?
     
  13. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    205
    If that Scene is in Addressables that it will be fine.
    Yes, anything outside of Addressables will be duplicated. Though references to the Mixer from content in Addressables is fine.
     
  14. FuriousEX

    FuriousEX

    Joined:
    Mar 13, 2014
    Posts:
    38
    The Mixer is in my launcher scene - the one scene in the build list, and so not addressable. So to make this work the way you all intend I would need to load the mixer into my launcher scene via addressables, right?

    I'd like to reiterate that this kind of workflow is not good.
     
    JokerDen and MarcBaques like this.
  15. FictiveDev

    FictiveDev

    Joined:
    Aug 14, 2019
    Posts:
    6
    I can agree that this is quite an unexpected effect. Addressables shouldn't be an all or nothing solution (e.g. make all scenes addressables).
     
unityunity