- Home /
In a split screen game, how to deliver different 3D sound?
Hey guys, so Unity3D does only support one audio listener in scene. But when developing a split screen game (like Rocket League), two different players may hear different sound since they are in different locations. But this explosion happens at the same time, same frame. Then how to make sure both players get the correct sound information (3D, so it's more about location)?
Answer by Deuce2008 · Oct 27, 2020 at 10:05 PM
So I like you am creating a split-screen game and found this question because I had the same problem. Now I know this is a REALLY REALLY old question but, I found a way to fix it, instead of two audio listeners, make an empty object and add a audio listener component to it. Next reset it's transform, then in your script that plays audio create a public Game Object like below:
public GameObject audioSpot;
public AudioClip Clip;
void Update()
{
audioSpot.transform.position = transform.position;
AudioSource.PlayClipAtPoint(Clip, audioSpot.transform.position);
}
Then drag in the audio listener object and play the clip at its position.
Hope this helps!
Sure bro, this is pretty helpful.
Unfortunately, I don't feel like implementing any of the solutions RN. Will have to make full systems next time I am planning a split screen game.
Has this ended up working? I'm trying it myself but I'm not sure which clip plays audio... I made the empty game object and put an audio listener in it but that is as far as I've got.
So say you have a gun, and want to make a noise when it fires, do this:
//This is the var that your object with the audio listener will go in
public GameObject audioSpot;
//your Music file goes here
public AudioClip GunClip;
void Update()
{
//This checks if you left click.
if(Input.GetButtonDown("Fire1"))
{
//This calls the Shoot() function.
Shoot();
}
}
void Shoot()
{
//This will move the Audio Listener to the gun's position.
audioSpot.transform.position = transform.position;
//This will play your clip at the Audio listener's position.
AudioSource.PlayClipAtPoint(GunClip, audioSpot.transform.position);
}
I hope this helps. If you still need help feel free to ask. (:
Okay, thanks so far! I'm not the greatest coder so I'm a little stuck. Each item that makes a sound would need this separate bit of code added to it?
Answer by coderxx · Dec 17, 2015 at 11:03 AM
Updated Answer: http://forum.unity3d.com/threads/multiple-cameras-and-audio-listeners.117130/
public Transform _AudioListener;
public void SetCamera( int camNum )
allCams[renderCam].enabled = false;
allCams[ camNum ].enabled = true; // enable the selected camera
// attach audio listner to camera
_AudioListener.parent = allCams[ camNum ].transform;
// align audio listener to camera (do after parent)
_AudioListener.localPosition = Vector3.zero;
_AudioListener.localRotation = Quaternion.identity;
renderCam = camNum; // save the current camera index
Older answer: You need to add an audio listener to each camera. Then choose the audio-source for each camera according to your liking.
This camera would 'be on each user's Player Controller and should give you what you need.
Edit, sorry, just realized the issue with Unity multi-audio listeners. This has been a hugely requested feature and multiple audio listeners is an issue with Unity. So refer to the discussions below.
http://forum.unity3d.com/threads/multi-audio-split-screen-audio-plugin-beta.165694/ http://forum.unity3d.com/threads/multiple-cameras-and-audio-listeners.117130/
Also, here is a list of search on Unity answers. Any combination of these can help your particular issue.
Answer by Max_Bol · Nov 18, 2016 at 08:10 PM
The ugly reality about splitscreen in Unity is that you can't use its native 3D sound system on each camera. The reason is that there's no priority system that runs outside of the Sound Listener system so if you had 2 Sound Listeners, the engine wouldn't know which one is "loudest" and if it were to play both, the sound would always play twice at different volume if the the "players" are close to each other. There's also the issues that Audio card on PC or console have a limited amount of channels. Using 2 Sound listeners would requires that both separate the available sound channels equally, making the game using 2x more sound channels (or dropping the capacity by half).
We're still waiting for a Audio Manager that could manage such a thing internally since as earlier as 2007.
So, to make a splitscreen that has 2 different camera, you got to create your own 3D sound system that manage such a things as the proximity + priority of each 3D based sounds.
First, you got to "unify" the sounds listener. This can be done in multiple ways, but the most important point that join them all : only 1 audio listener. Then you got to put a priority system as to how loud each sound should be based on each "players" position.
If I had to put it my own vision of one possibility, that would be to build an invisible "audio world". You create an "AudioWorld" empty game object which has the AudioListener component and whenever something can make a sound exists, you create an empty child to that game object that represent that something with the sound source component. An easy way of doing this is to create a script that can be placed on every "somethings that make a sound".
That script would or could :
1) Create the AudioWorld's child game object that represent the source of the sound.
2) Update the child game object transform based on distance between the players.
Note : This part can be done 3 ways. Either you compare the distance between each splitscreen players positions and the source of the sound and uses the closest (loudest) for the child transform relative position OR you make an average of both distance and put it in the middle. Both ways have their good and bad side. The closest method make the furthest player unable to know how far the sound was from or which way it was from while the average method makes both players unable to really guess the distance or actual direction. The last way is to generate 1 child in the AudioWorld for each player, but each with a slight variation on the axis based on how the screen is split and play both of them.
3) Make sure that whenever the "sound source" which dictate its AudioWorld child position is destroyed, that the said child gets destroyed first, otherwise you'll end up with a tons of useless gameobject with sound sources in the AudioWorld. Best bet is to manage the destruction of any gameobject through a function on each game object that manage the destruction instead of just calling in Destroy(GameObject). (Something like GameObject.GetComponent().StartDestroySequence(); which would include the StartDestroySequence() function that would know what has to be destroyed/removed from the scene. You could even fit the whole AudioWorld child instantiation system through that ObjectInstanceManage script if you wanted.)
Anyway, for anyone looking for a splitscreen audiolisters simulation, that's the general way of doing it with Unity. Yeah it's a pain in the butt but you got to think that they couldn't include it because, as I explained it, there's too many ways of handling it and, ultimately, there's no ultimate perfect way that will please everyone. (Like X Game would want it so that every sounds from every local player perspective and would have to be able to manage a slightly variation of each sound based on how the screen is split while Y game would want it for that it plays only once on the closest while Z game would want it to be average.)
Lastly, if you really don't want to manage all the sounds through each player perspective, you could just turn off the 3D sounds and play every sounds in 2D/Mono.
Answer by DemonWhisper · May 02, 2019 at 09:06 PM
"The ugly reality about splitscreen in Unity is that you can't use its native 3D sound system on each camera. The reason is that there's no priority system that runs outside of the Sound Listener system so if you had 2 Sound Listeners, the engine wouldn't know which one is "loudest" and if it were to play both, the sound would always play twice at different volume if the the "players" are close to each other. "
However, Unity could easily provide a solution to this, simply implement a mixer that sits after the audio listeners in the signal chain and allow to add audiolisteners as audio channels to this mixer.
"There's also the issues that Audio card on PC or console have a limited amount of channels. Using 2 Sound listeners would requires that both separate the available sound channels equally, making the game using 2x more sound channels (or dropping the capacity by half)."
This is not true at all. This issue has absolutely zero to do with audio cards, it is not a hardware problem but solemnly a software issue within unity. Mixing together two audio channels is as easy as simply adding the audio-signals together, then 2 signals become 1 signal, you don't even need an audio card to do that a CPU is more that capable. The only thing you need an audio card for is for converting analog signals to digital in order to provide mic-input or for converting digital signals to analog for audio output. When you look at an audio card specification and it is specifying a certain number of audio channels that would be the number of physical inputs and physical outputs that the audio card provides, this usually comes down to a mic input a line input and a stereo output. Any stereo signal will always only have exactly 2 channels, left and right.
Some big external audio cards meant for professional audio production will provide more than this, so you could have a big external audio card with 8 input channels and 8 output channels, which would allow you to input 8 different signals for example from mics, guitars, synthesizers, drums, etc. to do a big recording, and you could send 8 different audio signals to 8 different audio outputs so that you could hook them up to different external effect processing units or different channels on an actual physical analog hardware mixer. It has nothing to do with the amount of audio signals that your computer can handle internally, any computer can virtually handle an infinite amount of audio signals.
Your answer
![](https://koobas.hobune.stream/wayback/20220612000318im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I use Unity's Doppler effect with high velocity objects? 1 Answer
Max amount of simultaneous, hearable sounds? 1 Answer
Best way to play many audio clips at the same time? 0 Answers
Mute/Unmute not working with new sounds 2 Answers
Audio listener to mono then to left or right speaker? 2 Answers