Audio Mixer and asset bundle

Hello,

I have a problem with the audio mixer and a scene loaded as asset bundle.

I have my scene 1(who are in my game build) who contain some audio source and the output of the audio source is correctly linked to my audio mixer.

On my scene 1 , no problem with the audio

Now, i download my asset bundle scene 2 who contain also some audio source and where the output is also correctly linked to my audio mixer. But here the audio source don’t get the audio mixer volume parameters.

Also, if i don’t download my scene 2 as asset bundle and use the scene 2 from the build settings, everything work fine and when the game is running, if i click on the output of my audio source on my scene 2 unity show correctly my audio mixer in my project window. But if i download the asset bundle scene 2 and click on the output of my audio source, nothing is shown in my project window like a ghost audio mixer.

Seem like an audio source linked to a mixer and downloaded as asset bundle don’t work.

Maybe someone have the same problem?

Thank you

1 Like

Having this problem as well with Unity 5.1.2. Our audio designer is adding custom configured audio sources and mixers in scenes that we export as asset bundles for dynamic loading in our application. However, it seems like those don’t get exported correctly in the asset bundles. Additionally I have noticed a couple of other oddities:

  1. If I load the bundle in the editor, it seems to play the audio at its original levels. You can see in the audio mixer panel that the connection between the audio source and the mixer is not present.
  2. If I load the bundle in a published version of the app, it appears to play the audio at the correct levels (as was originally set in the mixer prior to being exported in the loaded scene), however I can’t actually verify this since I can’t see the audio mixer panel.

I would love to know from Unity if this is intentional, or if this is some kind of bug. I hope what’s happening is that it’s a bug just in the editor and that published builds are correctly adding the mixer, but I can’t tell that for sure and so I am worried about trying to ship anything that just seems to sound ok.

Edit: Same problem as this thread: Asset Bundle does not contain audio mixer - Unity Engine - Unity Discussions

I’m happy to see that i’m not the only one to have this bug.

I have tried everything during 3 days, and now i’m sure that if you have a scene exported as bundle with an audio source linked to your main mixer, when you download you asset bundle scene, the audio source don’t recognize your main mixer and don’t take the volume of it but a the volume of an default mixer.

Would be cool if someone from unity can check that.

Thank you

1 Like

Looks like I’m the fourth person here with this same exact problem. I really hope Unity dives into this ASAP. Our dev team is in the middle of upgrading from 4.6 to 5.1, this is making us pretty much come to a stop in terms of audio.

Yeah it’s annoying not being able to debug mixer levels in the editor even though it somehow works in the standalone build.

1 Like

Up, would be cool if someone from the unity staff check this post.

Thank you

1 Like

Has anyone filed an actual bug report? If so, what’s the bug number?

Hello superpig and thank you for your answer.

Unfortunately i don’t have send any report file because i have already send a file for some other problems and i have never seen it in the issue tracker, so i’m a bit tired of that.

Also, the others guy and myself have explained the problem here in detail.

To reproduce it, it’s really simple.

Your project must have :

////////////////// Setup ////////////////////////////////

  • 2 scenes, the scene 1 included in your build , the scene 2 exported as asset bundle (we will download and load it after).
  • 1 Audio Mixer setup like this https://unity3d.com/learn/tutorials/modules/beginner/5-pre-order-beta/exposed-audiomixer-parameters?playlist=17096
  • You scene number 1 must contain an audio source and the output need to be linked to “sound effect” as exemple (we will use a loop sound so check “loop” and “play on awake” for testing).
  • You scene number 2 must contain an audio source and the output need to be linked to “sound effect” as exemple (we will use a loop sound so check “loop” and “play on awake” for testing).
  • In your scene number 1, add a slider to change the volume of your Audio Mixer.
  • In your scene number 2, add a button to download and load your scene 2.
  • Export your scene number 2 as asset bundle and upload it to a server.

////////////////// Testing it ///////////////////////////////////////

  • Build your project who only include the scene 1 and run it.
  • Your project start with the scene 1 and you can hear your sound loop.
  • Reduce the volume of your audio mixer with your slider.
  • Download and load your scene 2.
  • Now , normally you can hear your sound exactly like in the scene 1 and the volume is not reduced.

I will try to make a new project and to send it if i have the time but i’m a bit busy at the moment.

I know that it’s maybe hard to understand when we are not confronted to the the bug, but i’m sure that a guy from the audio team will easily understand that when you download and load a scene from an asset bundle linked to an audio mixer, the link is broken and when the scene is loaded a “ghost or default” audio mixer is created with the default volume and don’t refresh the actual value of your main audio mixer.

Anyway, thank again and have a good day.

At a quick read-through, this sounds like user error / working-as-designed to me. When scene #2 references the AudioMixer asset, a copy of that AudioMixer is packed into the AssetBundle in exactly the same way as any other asset - i.e. if scene 1 uses a texture that scene 2 also uses, and you pack scene 2 into a bundle, it’ll pull a copy of the texture in with it.

To solve it you need to pack the AudioMixer itself into a ‘common’ bundle - and possibly to pack scene #1 into a bundle as well, so that both scenes #1 and #2 are depending on the same AudioMixer in the common bundle.

We’ve got a big sample/tutorial/guide thing to AssetBundles due out in the next week or two which should explain all this, and we’re going to build some tools to help you track down when this kind of duplication is happening.

1 Like

Thank for your answer.

All my asset bundle scene contain my audio mixer ( i have linked my mixer to a script in my asset bundle scene) and to solve my problem, i call this when my scene is loaded.

MyMixer.SetFloat ("Master", 20f);
MyMixer.SetFloat("Music",PlayerInfo.MainPlayer.Music_Sound);
MyMixer.SetFloat("SoundEffects",PlayerInfo.MainPlayer.Effect_Sound);

This code solve my problem in most case (I have again some problems if a sound is played before i call this function when my scene is loaded) and i call it also when i want change the volume inside a downloaded scene.
I just get a warning message when i use it in the editor and then the audio mixer get a default value.

But i think that it’s normal in the editor,not sure.

Thank again.

I also have a problem of this kind.

I have a scene, where I can set the volumes of the AudioMixers Audio groups.
Then I load another scene, where AudioSources link to these groups. Dynamicly, I also load objects (NPCs) that have AudioSources that link to an audio group of the mixer.

Both scenes and the NPCs are in asset bundles. I also followed superpigs suggestion and made the AudioMixer its own AssetBundle.
After loading the scene, I set the volumes of the audiogroups. This seems to work for the sources in the scenes but not for all audio sources on the NPCs loaded during scene play. These seem to keep their own audio group volumes.

I really really hope this is some kind of bug and not intended behavior to keep track of the Mixer of every asset I load. It’s also unlike all the other config-stuff. Input, QualitySettings, Graphics … everything is a static thing, consistent through scene changes. But the AudioMixer seems so wonky to use in combination with asset bundles…

EDIT: The documentation is also not helpful on this topic. Unity - Scripting API: AudioMixer talks about the AudioMixer being a singleton. But it doesn’t seem to be this way seeing how different bundles can have their own copy of an AudioMixer

1 Like

No asset bundles related, but had a similar problem. Our first scene plays a sound using an AudioMixer with custom volume right after the AudioMixer was loaded from Resources and the volume was set. This somehow broke the mixer and the volume never worked. Added a one frame wait before playing the sound and now everything works fine.

I’m having a closely related but slightly different problem. In my setup, I have create an AudioMixer asset with some snapshots, call them A and B. In my code, I have some logic that triggers when to play these snapshots. All is working as expected when I simply build and run the scene.

However, when I export the scene as an AssetBundle, then load it in to a blank scene, it looks like all the levels in the snapshots A and B have been returned to their default values. For instance,
Levels for snapshot A should look like this
But after AssetBundle import, they look like this…

More than 2 months now that i have posted this bug.
But for the unity team everything is working … yeah paul call jack who call tom who ask to adam if he know this bug…
I’m really disappointed since Unity 5 is out, too much bug are present and when they solve one , two another bug come.
where is the time of the 4.x.x …
For me, i have started to switch to an another engine. Unity seem to be so nice on the paper but in your hand , it’s something else.

Other bug without any answer if you want check …

Before i release my game i test it before, not the case for unity staff : Input Caret - Unity Engine - Unity Discussions
And this one, i’m sure that it’s related to the new option in unity 5 “Prebake Collision Meshes” : Unity 5 Mesh collider issue - Unity Engine - Unity Discussions

I have the same problem, but the editor works perfectly, but when compile the problem appears to android.

Any workarounds to avoid this bug? I have tried to pack whole sounds and audio mixer in one bundle but it didn’t help. How to link audio sources properly to right audiomixer? If it is designed behavior please describe somewhere how to manage a copy of audiomixer which bundled asset is using because according to current documentation audio mixer is singleton

Hello everybody i enctounered a similar bug with assetbundles and audiomixern and fixed it.
maybe this will help some of you (i think for some of you already too late, but for those who come to this thread, like me)

I had an Audiomixer and groups for the whole game and changed ambient/sfx/dialouges with snapshots.
Some of my snapshots were stored in assetbundles.

It seems that serialized references to parts of an AudioMixer cant be stored (/serialized) in assetbundles as references (maybe the Hashes changes dont know that one).
In my case i could fix it with storing the name of the snapshots (as strings) and not the references → successfull (as you can get Snapshots by their name, from an Audiomixer).

Additionally (didnt tested this one), be aware of the “stripping”-ability of unity: not integrating unnecessary code/assets (in my case i builded a “dead” script with a List-Field of all Snapshots i used).

if you encounter a similar issue with other parts of AudioMixer and Assetbundles, try to reference those parts in an array or sth like that and only store int ids.

Hope i helped someone

1 Like

For people still experiencing this or finding it out, here is some code implementing @Mest 's fix.
In resources, make this asset:

    public class AudioGroupBinding : ScriptableObject
    {
        private static AudioGroupBinding instance;

        public static AudioGroupBinding Instance
        {
           get {
              if (instance == null)
              {
                 instance = Resources.Load<AudioGroupBinding>("Your/Path/Here/AudioGroupBinding");
              }
              return instance;
           }
        }
        public AudioMixerGroup[] GroupReferences;

        public AudioMixerGroup ResolveMixerGroupID(int id)
        {
            if ((uint) (id - 1) >= (uint) GroupReferences.Length) return null;
            return GroupReferences[id-1];
        }

#if UNITY_EDITOR
        public int GetOrCreateMixerGroupID(AudioMixerGroup group)
        {
            if (group == null) return 0;

            for (int index = 0; index < GroupReferences.Length; index++)
            {
                if (GroupReferences[index] == group)
                {
                    return index+1;
                }
            }

            Array.Resize(ref GroupReferences, GroupReferences.Length + 1);
            GroupReferences[GroupReferences.Length - 1] = group;
            EditorUtility.SetDirty(this);
            return GroupReferences.Length;
        }
#endif
    }

Then, in a common location, add this script:

    [Serializable]
    public struct MixerGroup
    {
        public int groupID;

        public AudioMixerGroup Group { get; private set; }

        /// This must be called in Awake().
        public void Resolve()
        {
            Group = AudioGroupBinding.Instance.ResolveMixerGroupID(groupID);
        }

        public static implicit operator AudioMixerGroup(MixerGroup mixer)
        {
            return mixer.Group;
        }
    }

In each asset that needs to reference an AudioMixerGroup, put

public MixerGroup Output;

private void Awake()
{
    Output.Resolve();
}

And finally, add a custom editor so it looks like it’s just an AudioMixerGroup

    [CustomPropertyDrawer(typeof(MixerGroup))]
    public class MixerGroupPropertyDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            property.NextVisible(true);
            Assert.AreEqual("groupID", property.name);
            int value = property.intValue;
            var binding = AudioGroupBinding.Instance;
            var oldGroup = binding.ResolveMixerGroupID(value);
            var newGroup = (AudioMixerGroup) EditorGUI.ObjectField(position, "Output", oldGroup, typeof(AudioMixerGroup), false);
            if (newGroup != oldGroup)
            {
                property.intValue = binding.GetOrCreateMixerGroupID(newGroup);
            }
        }
    }
1 Like

Recently ran into this issue as well, but it wasn’t just about the bundles. I was trying to TransitionTo another AudioMixerSnapshot immediately on level load or Awake, which just doesn’t work.
Changing from Awake to Start solved the issue.

Hello, I ran into the same problem today and found the following fix. It’s not as elegant as the previous one, but definitely more concise (and understandable for newbies)

My case:
I setup an AudioMixer that was referenced by both build scenes and addressable assets.
As such, scenes and bundles referenced two differents copies of my AudioMixer asset.
This means that when I was trying to set the AudioMixer’s parameters, I was only updating 1 of the two copies (the one being updated depending on how I referenced the AudioMixer asset for modification).

My solution:
I stuck to bundling my AudioMixer with my assets but figured I should fix the AudioMixer reference on all AudioSources in my scenes when loading!

public static class SceneAudioMixerInitializer {
  public static void FixMixerOnAllAudioSourcesInScene() {
    // Get all of the scene's audio sources
    AudioSource[] audioSources = Object.FindObjectsOfType<AudioSource>();

    // Loop through them
    foreach (AudioSource audioSource in audioSources)
      FixMixerOnAudioSource(audioSource);
  }
     
  private static void FixMixerOnAudioSource(AudioSource audioSource) {
    // Ignore audio sources without a mixer group
    if (audioSource.outputAudioMixerGroup) {
      // Extract the ghost group's name
      AudioMixerGroup outputAudioMixerGroup = audioSource.outputAudioMixerGroup;
      string groupName = outputAudioMixerGroup.name;
      string mixerName = outputAudioMixerGroup.audioMixer.name;

      // Use group and mixer names to find the real group among the bundled ones
      audioSource.outputAudioMixerGroup =
        AssetsManager.AudioMixers[mixerName].FindMatchingGroups(groupName)[0];
    }
  }
}

Before calling FixMixerOnAllAudioSourcesInScene, I load my AudioMixer assets in AssetsManager.AudioMixers from my Addressables (yeah I had multiple AudioMixer assets, not just one, I simplified the case for clarity)

So whenever I load a new scene, I check if my AudioMixers are loaded in my AssetsManager and I then call FixMixerOnAllAudioSourcesInScene before any sound can play!

Hope this will help someone because this sure was a headache :c

3 Likes