Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Audio Mixer and asset bundle

Discussion in 'Audio & Video' started by roka, Jul 2, 2015.

  1. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    457
    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
     
    DizzyWascal likes this.
  2. InfiniteLee

    InfiniteLee

    Joined:
    Dec 11, 2014
    Posts:
    4
    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: http://forum.unity3d.com/threads/asset-bundle-does-not-contain-audio-mixer.344231/
     
    Last edited: Jul 29, 2015
  3. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    457
    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
     
    DizzyWascal likes this.
  4. tfodorsound

    tfodorsound

    Joined:
    Jun 12, 2015
    Posts:
    12
    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.
     
  5. bleu

    bleu

    Joined:
    Apr 6, 2013
    Posts:
    41
    Yeah it's annoying not being able to debug mixer levels in the editor even though it somehow works in the standalone build.
     
    tfodorsound likes this.
  6. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    457
    Up, would be cool if someone from the unity staff check this post.

    Thank you
     
    bleu likes this.
  7. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,215
    Has anyone filed an actual bug report? If so, what's the bug number?
     
  8. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    457
    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.../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.
     
  9. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,215
    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.
     
  10. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    457
    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.

    Code (CSharp):
    1.  
    2. MyMixer.SetFloat ("Master", 20f);
    3. MyMixer.SetFloat("Music",PlayerInfo.MainPlayer.Music_Sound);
    4. 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.
     
  11. GameArt Philipp

    GameArt Philipp

    Joined:
    Oct 18, 2013
    Posts:
    18
    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. http://docs.unity3d.com/ScriptReference/Audio.AudioMixer.html 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
     
  12. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    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.
     
  13. Jeanbon

    Jeanbon

    Joined:
    Nov 7, 2012
    Posts:
    2
    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...
     
    Last edited: Sep 17, 2015
  14. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    457
    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 : http://forum.unity3d.com/threads/input-caret.355252/
    And this one, i'm sure that it's related to the new option in unity 5 "Prebake Collision Meshes" : http://forum.unity3d.com/threads/unity-5-mesh-collider-issue.355622/
     
  15. fingersjuegos

    fingersjuegos

    Joined:
    Sep 21, 2015
    Posts:
    1
    I have the same problem, but the editor works perfectly, but when compile the problem appears to android.
     
  16. anton-melegov

    anton-melegov

    Joined:
    Jun 18, 2015
    Posts:
    10
    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
     
    Last edited: Nov 23, 2016
  17. Mest

    Mest

    Joined:
    Nov 7, 2012
    Posts:
    7
    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
     
    pb_martinwickham likes this.
  18. pb_martinwickham

    pb_martinwickham

    Joined:
    Mar 9, 2017
    Posts:
    5
    For people still experiencing this or finding it out, here is some code implementing @Mest 's fix.
    In resources, make this asset:
    Code (CSharp):
    1.     public class AudioGroupBinding : ScriptableObject
    2.     {
    3.         private static AudioGroupBinding instance;
    4.  
    5.         public static AudioGroupBinding Instance
    6.         {
    7.            get {
    8.               if (instance == null)
    9.               {
    10.                  instance = Resources.Load<AudioGroupBinding>("Your/Path/Here/AudioGroupBinding");
    11.               }
    12.               return instance;
    13.            }
    14.         }
    15.         public AudioMixerGroup[] GroupReferences;
    16.  
    17.         public AudioMixerGroup ResolveMixerGroupID(int id)
    18.         {
    19.             if ((uint) (id - 1) >= (uint) GroupReferences.Length) return null;
    20.             return GroupReferences[id-1];
    21.         }
    22.  
    23. #if UNITY_EDITOR
    24.         public int GetOrCreateMixerGroupID(AudioMixerGroup group)
    25.         {
    26.             if (group == null) return 0;
    27.  
    28.             for (int index = 0; index < GroupReferences.Length; index++)
    29.             {
    30.                 if (GroupReferences[index] == group)
    31.                 {
    32.                     return index+1;
    33.                 }
    34.             }
    35.  
    36.             Array.Resize(ref GroupReferences, GroupReferences.Length + 1);
    37.             GroupReferences[GroupReferences.Length - 1] = group;
    38.             EditorUtility.SetDirty(this);
    39.             return GroupReferences.Length;
    40.         }
    41. #endif
    42.     }
    Then, in a common location, add this script:
    Code (CSharp):
    1.     [Serializable]
    2.     public struct MixerGroup
    3.     {
    4.         public int groupID;
    5.  
    6.         public AudioMixerGroup Group { get; private set; }
    7.  
    8.         /// This must be called in Awake().
    9.         public void Resolve()
    10.         {
    11.             Group = AudioGroupBinding.Instance.ResolveMixerGroupID(groupID);
    12.         }
    13.  
    14.         public static implicit operator AudioMixerGroup(MixerGroup mixer)
    15.         {
    16.             return mixer.Group;
    17.         }
    18.     }
    In each asset that needs to reference an AudioMixerGroup, put
    Code (CSharp):
    1. public MixerGroup Output;
    2.  
    3. private void Awake()
    4. {
    5.     Output.Resolve();
    6. }
    And finally, add a custom editor so it looks like it's just an AudioMixerGroup
    Code (CSharp):
    1.     [CustomPropertyDrawer(typeof(MixerGroup))]
    2.     public class MixerGroupPropertyDrawer : PropertyDrawer
    3.     {
    4.         public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    5.         {
    6.             property.NextVisible(true);
    7.             Assert.AreEqual("groupID", property.name);
    8.             int value = property.intValue;
    9.             var binding = AudioGroupBinding.Instance;
    10.             var oldGroup = binding.ResolveMixerGroupID(value);
    11.             var newGroup = (AudioMixerGroup) EditorGUI.ObjectField(position, "Output", oldGroup, typeof(AudioMixerGroup), false);
    12.             if (newGroup != oldGroup)
    13.             {
    14.                 property.intValue = binding.GetOrCreateMixerGroupID(newGroup);
    15.             }
    16.         }
    17.     }
     
    Mest likes this.
  19. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    197
    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.