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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

Master Audio - AAA Sound Solution. #1 audio plugin on Asset Store!

Discussion in 'Assets and Asset Store' started by dark_tonic, Jan 28, 2013.

  1. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    310
    Porting our game to Switch and noticing that PlaySoundAtVolume function is relatively expensive when used. Noticing that the Dictionary GetItem and Contains item is a decent part of the cost, wondering if there would be any gain to be able to play sounds with a int hash instead of a string, as with animators and shader properties?
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    I'm not sure how we would do an int hash given that they all have string names (Sound Groups). That could lead to weird bugs. Dictionary is the most efficient algorithm to use here.
     
  3. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    310
    Would probably involve caching their names to int hashes on start and doing hash compare instead of string compare. Then when calling to play a sound you would send the int hash (that was cached on start) instead of the string. Very much how Unity does it with the Animator system where you can set variables to the animators with both string and int hash.

    Basically MasterAudio would turn the sound group names into int hashes on startup and users would play sounds with int hashes that matches. Shaders and Animators work with both string and int hash, int hashes are more a pain to work with but way more performant.

    Example for how animators work and the performance gain from comparing int hashes vs strings.
    https://forum.unity.com/threads/animator-dont-use-setbool-string-name-with-string-parameter.406286/
     
  4. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    It's not something I'm keen to do, thanks for the explanation though.

    If you wanted to try and see what the performance difference would be through your own work, I'll take a look. We haven't heard of this even through our numerous AAA clients using Master Audio.
     
  5. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    310
    Yeah I get that, just a suggestion as alternative functions to the string functions. Might be worth a try to see how much of a performance difference it is.
     
  6. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Yes. I mean I've been through performance profiling many times on Master Audio, and it's pretty performant *on my computer*. We've eliminated all allocations possible that we know of.

    I'll put it on the roadmap. Thanks.
     
  7. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    310
    Yeah on a PC this isn't a problem. Or any decent platform for that matter. I'm porting to Switch however which is basically a glorified Ti-82 calculator.
     
  8. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Haha, wow. Takes me back to high school in '91.

    Thinking about it, I'm really not sure how we would do this. The thing is, users' scripts already have the Sound Group name, and not some int, when asking Master Audio to play sounds. Without that changing (and it really can't), I'm not seeing how we can obtain the correct int mapped to the string.
     
  9. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    310
    I haven't checked how it's serialized but you couldn't generate a int hash for all sound groups on Master Audio startup? And you can't convert it for everyone automatically, that is true, but you could generate the hash on start and have it as a alternative function to the regular PlaySound(string) as a PlaySound(int). Then users could chose to use the int hash function if they require the extra cpu performance.

    That's how both Shader and Animators have it. Both string and int functions are available.
     
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    It wouldn't work for EventSounds, which does 95% of the work for most projects. It only knows the names of Sound Groups - it also requires to ability to specify the name of a Sound Group not currently in the Scene (for Dynamic Sound Group Creators to work). It would have no way to know the number of an as yet uncreated Sound Group. And I definitely am not going to have it work 2 ways. I don't think it's feasible unfortunately.
     
  11. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    310
    Ah yeah then I understand. I see the problem. Well as you said it wouldn't be a huge performance boost anyway. Was just a thought while profiling.
     
  12. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Cool, let me know if you see anything else.
     
    Zilk likes this.
  13. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    486
    Hi @jerotas,

    Using MA 2022 -> just a heads up, I might have messed up but I don't see how as I deleted all Master Audio folders and re-imported the asset to test.

    The master audio prefab was empty like a script error and when trying to add the Master Audio script to a game object it was telling me "it's an editor script"

    I figured out after some troubleshooting that your MAScripts Assembly was wrongly set as an editor script (see screenshot)

    I tried again deleting all Master Audio folders. Re-imported: Working. Then imported the ASMDEF package: Not working again because the runtime assembly is marked as Editor only.

    Can you check on your side if that's the case? not a big deal now that I know

    upload_2022-3-31_21-13-25.png
     
  14. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Sure, let me know which of the 4 asmdef packages you installed please. Is that the one without addressables and without Core Gamekit?

    MA_asmdefs?
     
  15. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    486
    Oh sorry you're right I forgot that. It's the basic one yes, not one with any integration
     
  16. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Ok I'll be fixing it for the next update, thanks.
     
  17. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    There is a Unity Event, "On Damage Taken ()," on a Damage Receiver object on my character controller. Can I use it to trigger the one time playing of an audio clip that resides in Assets?
     
  18. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    If you set up the audio clip in a Sound Group in Master Audio, you could write a 1-liner to play the Sound Group with the Master Audio API.

    Does that answer your question?

    -B
     
  19. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Sort of... My issue is that the Damage Receiver event loses its connection to the sound clip (in assets), when the Player dies. So I was thinking that if I set up the audio clip in a Sound Group on my player, I could use the event to call the clip in the sound group, which would continue to be connected after respawn, because the sound group is a component on my Player, (unlike the original clip in the assets). Make sense? Is the sound group a component that can be on my Player Character?
     
  20. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Unity Event connections to components on the character controller, itself, survive death/respawn.
     
  21. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    No. That problem is precisely why audio middleware exists - one of the major reasons anyway. You won't have an audio anything on your player, definitely not a clip. Your Sound Groups exists outside of any "actor" in the Scene, they are their own thing. Your player will just tell Master Audio what Sound Group to play and who/what the actor is (your player).
     
  22. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    So I created a sound group, but I can't see a simple way to play it. I slotted the group into the OnDamageTaken() event on my player damage receiver which makes various functions available, but no Play(). I can get it working if I use your Event Sounds script and collider OnEnter(), but the sounds are inconsistent, due to the variety of NPCs and their colliders. I really need to fire the damage grunts from the Damage Receiver, if we can do that.
     
  23. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    I'm not even sure what you're attempting to do here from your description. You won't be able to use EventSounds since OnDamageTaken is not a stand MonoBehaviour event and we have no hooks in there for it.

    Do this:
    Add a public string for the Sound Group name in your script, decorated with the Sound Group attribute so it will have a dropdown in the Inspector.
    Code (csharp):
    1.  
    2. [SoundGroup]
    3. public string SoundGroup;
    4.  
    Then, on your OnDamageTaken method you can play it, with the standard Master Audio API call.
    Code (csharp):
    1.  
    2. MasterAudio.PlaySound3DFollowTransformAndForget(SoundGroup, this.transform);
    3.  
     
  24. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Flash sale on Master Audio 2022 today only! 70% discount at only $24 for the full version! Grab it now (or more licenses if you need them).
     
    TonyLi likes this.
  25. profuzzy

    profuzzy

    Joined:
    Mar 13, 2015
    Posts:
    27
    @jerotas -is there by chance, a 2021 v. 2022 feature comparison or (an any level, aka: in depth or overview) feature listing for each package ?
    I'm having trouble finding anything of this type and I've been jumping around trying to piece this together on my own.
    Thx

    P.S. Also, what does "All new for 2022" actually mean ? Did you do a full rewrite of the systems ?
     
    Last edited: Apr 23, 2022
  26. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    There's no full rewrite. The part that's all new for 2022 is just the ability to loop a section of a song, plus the dozens of bug fixes.

    As far as a comparison of the other products, well:

    1) We removed the Multiplayer version from the Asset Store. Free upgrade to MA 2022 will be available for users of that package indefinitely.
    2) Master Audio 2021 will be removed from the Asset Store in about a week. Upgrade to MA 2022 will be available to users of that package indefinitely for $20.

    Really, the intention is not to keep selling the old version(s) as bug fixes and more are only done in the newest version.

    Thanks,
    -Brian
     
  27. profuzzy

    profuzzy

    Joined:
    Mar 13, 2015
    Posts:
    27
    Thank you for the clarifications Brian. I appreciate your time.
     
  28. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Of course!
     
  29. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    I understand what you are advising, but I can't get the script right. If you help me, I will pay, or I could buy another seat for one of your assets. Here is the script:

    using UnityEngine;

    namespace NullSave.TOCK.Stats
    {
    [HierarchyIcon("damage", false)]

    public class DamageReceiver : MonoBehaviour
    {

    #region Variables

    [SoundGroup]
    public string SoundGroup;

    public DamageRecieved onTakeDamage;

    #endregion

    #region Properties

    public StatsCog StatsParent { get; set; }

    #endregion

    #region Public Methods

    public virtual float TakeDamage(DamageDealer damageDealer, GameObject damageSourceObject) { onTakeDamage?.Invoke(damageDealer, damageSourceObject); return 0; }

    #endregion
     
  30. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    No need. Here, I believe what you want to do is this:
    Code (csharp):
    1.  
    2. public virtual float TakeDamage(DamageDealer damageDealer, GameObject damageSourceObject) {
    3.        onTakeDamage?.Invoke(damageDealer, damageSourceObject);
    4.        
    5.        MasterAudio.PlaySound3DFollowTransformAndForget(SoundGroup, this.transform);
    6.  
    7.        return 0;
    8. }
    9.  
    10.  
     
  31. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Do I need a using Master Audio or something at the top?
     
  32. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Yes, using DarkTonic.MasterAudio;
     
  33. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    I don't get a dropdown?
     
  34. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Even with no MasterAudio game object in your Scene, you'd still get a dropdown with 2 options: [Type In] and [None].

    upload_2022-4-28_9-27-40.png
     
  35. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    I have Master Audio in my scene, and unfortunately, the MA_Player Control (Script) provides no Sound Group slots. They just aren't there.

    What if we forget the drop down, and I hard code the sound group name into the function? I have the Master Audio and a sound group GruntsPlayer correctly setup in the scene. What's the script line to play the group? I tried swapping "GruntsPlayer" in place of "SoundGroup" in the line you provided, but that did not work.
     
    Last edited: Apr 28, 2022
  36. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    It doesn't have to be that script, that's just where I added the following:

    Code (csharp):
    1.  
    2. [SoundGroup] public string SoundGroup;
    3. [/code
    4.  
    5. The SoundGroup attribute becomes a dropdown in the Inspector.
     
  37. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,394
    I tried exporting the demo scene from the latest Master Audio 2022 asset to WEBGL but getting a bunch of errors when Unity webgl player is initialized in the browser.

    Unity 2021.3 LTS windows 10

    Can you confirm that this asset works correctly for WEBGL?

    Cheers
     
  38. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    I just installed WebGL for the newest Unity, did "build and run" and the example Scenes seem to work fine. Did you try Build and Run?
     
  39. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    Does Master Audio 2022 currently work with Unity's first party networking solution (Unity Netcode for GameObjects, formally MLAPI)?

    If not, is there a plan to produce a "MAM_UnityNetcode" file?

    Thanks!
     
  40. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    No. Last I heard, that's not a full networking solution. Further things need to be built on top of it to be a full network solution. If my info is out of date, let me know.
     
  41. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    Thanks for getting back to me on this.
    Unity Netcode for GameObject is indeed a full networking solution - it is very similar to Mirror and UNET and it has become a lot more stable since version 1.0.0 got released.
     
  42. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Ok. Does it have RPC's? If so, it may be fairly easy to adapt. Also, do we know popular it is compared to Photon and the like?
     
    nico_st_29 likes this.
  43. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Master Audio 2021 package is now deprecated and removed from the asset store. There will be no further updates, although upgrades will be available indefinitely to Master Audio 2022. Currently that upgrade price is $20.

    -Brian
     
  44. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/messaging-system

    Essentially you need to call RPCs from a NetworkBehaviour script sitting on an object that also has a NetworkObject component and then they look like this for Server/Client respectively

    [ServerRPC]
    void ExampleServerRpc() {} // needs to end with ServerRPC

    [ClientRPC]
    void ExampleClientRpc() {} // needs to end with ClientRPC

    Re popularity: it's hard to say, 1300 are on the Discord server and in the last 2 updates Unity featured quite a few studios working with it or updating their UNET games to Unity Netcode for GameObjects. I expect it to grow quite a bit when it becomes built-in for 2022 LTS.
     
  45. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Thanks, I ask about the popularity because this is basically the 3rd multiplayer system we've been asked to support in the last month. Also FishNet and Photon Fusion. And we need to prioritize them in order of popularity.

    -B
     
  46. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    I figured: I can probably help you a bit with the addition of Unity's Netcode for GameObjects.

    FishNet is basically a better Mirror and it has a built-in converter to help convert existing Mirror projects to FishNet so that should help.
     
  47. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    Sure, any assistance you can provide would be wonderful.
     
  48. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    I'll work on a first quick and dirty version this week.

    On another note: I just replaced a bunch of SFX triggers done with my own system with their MasterAudio equivalents and I'm seeing quite a bit of lag between the button being clicked and the SFX playing. Any idea how I can improve that?
     
  49. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,491
    There is no latency unless you're deploying to Android. We even warm the code with a silent play of a sound effect during startup.

    So, can't reproduce over here.

    If it's compressed audio, that's a no-no, but that wouldn't be working faster with your code either.

    You'd need to send me a specific example scene for me to dig in.
    -B
     
  50. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    I just tried switching Audio Origin to "Clip" instead of "Addressable" and I don't get the above-mentioned delay.

    These are the settings on my sound effects:
     

    Attached Files:

unityunity