Fmod Unity Multiplayer 3d audio sync issue

Hi, I am facing an issue while syncing the player footstep 3d audio for a multiplayer game. The 3d audio is not working on distance based approach. I am trying to achieve that one player footstep audio should fade as he move away form another player position.
I am using Fmod for unity 2.02.11 version.
We tried " set3DAttributes" and “FMODUnity.RuntimeManager.AttachInstanceToGameObject” function approach but it is not working
Any suggestion on how to sync distance based audio for multiplayer

Hi!

Do you have a listener on both players? If so, you’ll be hearing an audio signal from both listeners at the same time, and the footstep audio wouldn’t fade as it’d always be playing at the same position as one of the listeners.

If this isn’t the case, and you only have a single listener on the player that isn’t moving away, can I get you to provide a snippet of the code where you’re handling your footstep event instance and using EventInstance.set3DAttributes() or FMODUnity.RuntimeManager.AttachInstanceToGameObject()?

Hi! @Louis_FMOD
Thanks for the response, We have listener on both players as it is a multiplayer network base FPS(First person shooter) game, so the each player that is spawned on the server is having a Fmod listener and a event emitter to play the 3d audio while it moves. The issue that we are facing is to sync these player footsteps in such a way that only player near to the other player will be able to hear the footsteps 3d audio.
It would be helpful if we come to know how we can implement Fmod audio in a multiplayer server game, Also If there are any links to such examples made in Unity3d would be much appreciated.

Thanks

While you can create multiple listeners in a single FMOD system, listeners aren’t discrete outputs for the system, but are used alongside event 3D attributes to calculate audio spatialization. If you have multiple listeners, FMOD will blend between their positions for the purposes of spatialization, which is likely why distance-based attenuation of your footsteps audio isn’t working. For more info, I’d recommend taking a look at the Multiple Listeners section of our Studio 3D Events White Paper.

Typically how network multiplayer games work with FMOD is to use the server to manage and coordinate events, while each client creates their own local FMOD system when running the game, with a listener for the player using that client. That way, while all events (i.e. your footsteps event) are coordinated by the server and are then played on each client’s FMOD system, the only listener used for spatialization for each respective client is attached to the player of that client.

Hope that helps!

Hi @Louis_FMOD
Thanks for sharing the knowledge ,This definitely helped us in understanding the challenges with FMOD for creating server based Multiplayer games audio system.
It seems that Handling multiple listeners in FMOD for a server based multiplayer game is not a great solution over the unity3d core audio API.
FMOD is suitable for standalone games and best for " edit in real-time" audio for sound engineers.
Also there are hardly any resources available with respect to FMOD 3D audio sync over network.

My wording was a little unclear, so to clarify, by “use the server to manage and coordinate events” I mean that the server is handling the overall state of the game; it isn’t actually syncing audio data across the network, or transmitting event instances over the network. Each local client receives the state of the game from the server, and then the local FMOD System handles event creation and management based on that game state, and calculates what the local player hears. Handling networked audio using Unity’s audio system will essentially involving doing the same thing. The main exception to this, in terms of audio, is something like voice chat, which does actually transmit audio across the network.

You can considering this to be analogous to how networked games handle most things that fall under a single client’s perspective, for example rendering a single player’s point of view: the client receives the game state in some form, but it doesn’t render what every player connected to the game is viewing at once - it only renders what the local player is currently seeing.

Hi @Louis_FMOD
Thanks for the response, your explanation definitely clarify our concepts. We want to use FMOD in our project as we can see lot of potential in FMOD from both audio creation and implementation perspective. But we are somehow facing challenges to implement multiplayer 3d audio sync using FMOD. Having said that it would be helpful if you can share some sample project or links on how to implement the FMOD audio for unity multiplayer FPS game.

Thanks

Unfortunately, we don’t have any examples or sample projects that demonstrate how to implement FMOD Studio audio with Unity Networking. However, in practice it’s not too difficult to implement, and is similar to how you would handle other kinds of client-specific behavior like cameras - you need a way to check whether the current game instance and specific objects in it belong to the server, a client, or specifically the local player, and you can tie behavior to those checks.

For a very basic example, assuming you have a simple network multiplayer game using Unity’s Netcode for GameObjects package, such as the project created in this Netcode for GameObjects tutorial - to only enable a listener on the local player when it is spawned, you would put an if (isOwner) check in the inherited method OnNetworkSpawn() of the player object’s NetworkBehaviour script, which will check whether the object belongs to the local player. If the object does belong to the local player, then you create/enable a StudioListener component.

For any calls to the FMOD system or events i.e. event creation, setting 3D attributes or parameters, etc. you’d likely want to wrap your FMOD-related calls in a check to ensure that they’re only executed on clients, and not the server. For example, you can create a GameObject with a NetworkObject component in the center of the scene, add a script that inherits from NetworkBehaviour, and set it to enable a StudioEventEmitter and play and event in OnNetworkSpawn() only if the game is executing as a client with if (isClient).

With the above checks in place:

  • The server doesn’t add any listeners or create any events

  • All clients execute functions related to FMOD - event creation and playback, setting 3D attributes, etc.

  • Each local client creates a listener on their respective “player” GameObject, but not on any other player GameObjects

I hope that makes it a little clearer.

As an aside, I agree that there’s hardly any resources out there for implementing FMOD Studio in network multiplayer games, so I’ve flagged the creation of some kind of example or sample project on our internal feature/improvement tracker.

Hi @Louis_FMOD
Thanks for your active response and also for adding our request to create some examples to your " internal feature/improvement tracker".
We are actively working on implementing FMOD for multiplayer game using Unity.
Hope so we find a solution for our challenges at earliest possible!.

Thanks once again for your support, We will keep you posted on the progress according .

1 Like

I currently have a full multiplayer game in Unity that uses PUN2. I just switched out the audio for FMOD and have it working using this code:

public void PlayFootSound(string path, int playerStance, int surfaceType)
{
    audioFire = RuntimeManager.CreateInstance(path);
    
    audioFire.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject.transform));
    FMOD.Studio.EventDescription reloadEventDescription;
    audioFire.getDescription(out reloadEventDescription);

    FMOD.Studio.PARAMETER_DESCRIPTION reloadParameterDescription;
    reloadEventDescription.getParameterDescriptionByName("Surface", out reloadParameterDescription);
    reloadParameterId = reloadParameterDescription.id;
    audioFire.setParameterByID(reloadParameterId, surfaceType);

    FMOD.Studio.PARAMETER_DESCRIPTION playerStanceParameterDescription;
    reloadEventDescription.getParameterDescriptionByName("PlayerState", out playerStanceParameterDescription);
    reloadParameterId = playerStanceParameterDescription.id;
    audioFire.setParameterByID(reloadParameterId, playerStance);

    
    audioFire.start();
    audioFire.release();
}

I experience all player footsteps right on my own player (as does any other client). I also noticed when other players load in, the source of the gunfire moves to where the last player loaded in at (say enemy team or bots on teams). I also have a reverb trigger in a room that when a player touches it, it activates reverb for everyone. Hopefully I can narrow down something with how 3dattributes work and any help from the fmod team. Thank you.
-Raymond

Hi,

Without access to your project to see exactly how you’ve set things up, it’s difficult for me to diagnose the issues you’re describing. That said, I can offer some general advice based on what you’ve noted.

This indicates that you’re likely handling either your listener or event positions incorrectly. You’ll want to ensure you only have a single listener that is placed on the local client’s player, as having multiple listeners, especially a listener on each player, would lead to the behavior you’re observing. You’ll also want to ensure that the position passed to audioFire.set3DAttributes() is respective to each player transform, as opposed to a single position (potentially the position of the last player to load in).

This indicates that you’re likely activating reverb for all events, as opposed to just the ones in the reverb zone. How exactly have you set up your reverb zone in FMOD Studio? Personally, to implement this I would do the following:

  1. Set up a return bus in your Mixer with a Reverb effect that represents your reverb zone
  2. Set up sends to that return bus on all events you want to potentially be subject to the reverb zone - event defaults or effect presets may be useful for this
  3. Add a “Reverb Zone” local parameter to those events, and automate the gain of the send with the parameter
  4. In game, set the “Reverb Zone” parameter on events that enter the reverb zone

Good morning,

Thank you for the quick reply. Would love to get the help to nail this down. I’ll walk you through what I have right now and how things are called. I most certainly do have things setup incorrectly lol.

On my main camera I have the FMOD Listener (this camera moves to the active player from PUN calling).

On the main In Game prefab (where main game loop is housed, to tell players UI calls and just run normal game functions), I have my FMOD_Weapons script which called PlayFootSound().

Inside my movement script this is what the old code to the new code looks like:

//Play
//pb.footstepSource.Play(); // OLD SOUND CALL

for(int i = 0; i< footstepIndexFMOD.Length; i++) 
{
    if(bogrd.currentMaterial == footstepIndexFMOD[i]){
        Nitro_FMOD_Weapons.Instance.PlayFootSound(footstepFPath, playerState, i);
    }
}

→ PlayerState tells fmod which stance the player is in based on INT (0 is standing, 1 is crouch, 2 is prone) and “i” represents the material. All of this works well.

Now this part of the script is done twice for multiplayer. This bogrd version is RuntimeData for the PUN owner of the player.
I have another that is done as SyncRuntimeData which is calling the same way, but this is the info synced via PUN (aka how I can hear footsteps from other players to begin with).

What I’m guessing is happening is I am incorrectly setting up the 3dattributes to tell it which position to load onto, so it’s taking the active player (say mine) and is just playing all sounds onto my system right where my body is. I think once I understand this setup I can fix the rest of my audio. So we can just focus on this.

Sincerely,

Raymond.

Good afternoon,

Great news, I went back in after re-reading what you were talking about and got it working. I think solved all the issues.
For starters I had set Attenuation Object to my In Game prefab. I took that off so it would be normal. I then placed a new Footstep FMOD script into the foot source like the old audio source was, so I can call on it for each player. Worked well and its spatial (confirmed via bots online).

Lastly I think I solved my issue with the weapons sound audio moving to the last player who loads in location. This had to do with creating an Instance of the FMOD_Weapons. I cannot do that since each player has this so I removed that, recalled scripts and yeah, sounds great!

FMOD with Unity multiplayer (PUN and soon I will try with Mirror) seems to work just fine! Thank you and hopefully this helps anyone else.

Sincerely,
Raymond

1 Like

Happy to hear that you managed to work out the issues with spatialization and your weapons sounds. Did you manage to resolve the problem with your reverb zone as well?

Not yet, I will momentarily!

1 Like