Audio stuttering

Hi, I am developing a game and testing it in my Unity editor (Windows 11).

In the game you are a person walking in streets and there are a lot of cars, so I made a script in Unity that checks if there are nearby cars (at max 5) every frame, and for each of them I do RuntimeManager.PlayOneShot(carEngineSound, carPosition).
For now I don’t even stop sounds if there aren’t enough cars nearby because I just installed FMOD today and I am still a noob, but I can see in the FMOD Studio Debug I don’t have memory issues or things like that.

Now when I test it (in the editor, can’t test in a build because of a Unity bug), the FPS is good (around 60 fps) but I hear a lot of stuttering in the sounds of the engine, like the car engine sounds are playing correctly but very frequently they are suddenly mute for some frames and then they become unmute… It’s unusable right now


Could I get you to provide a code snippet of how you’re calling RuntimeManager.PlayOneShot()?

This issue can be caused by having too many streaming assets streaming at once. When an asset it set to “stream” in FMOD Studio’s Asset browser, instead of being loaded into memory in its entirety before playback, the asset streamed from your storage media (i.e. loaded piece by piece on demand) during playback. This can be useful for saving memory, but most systems cannot support running a large amount of concurrent streams at once, which can lead to stuttering behavior like you’re describing. If the asset(s) you’re using for your event is set to stream in FMOD Studio, can you toggle it off and see if that resolves the issue?

The FMOD Studio Debug overlay only provides a general insight - if you want to look more in-depth at the performance of your FMOD Studio project, you should connect the Unity editor to the FMOD Studio application via Live Update and use FMOD Studio’s profiler, which will let you record and examine things like File I/O, event instances and lifetimes, virtualization, and more. Info on how to do this can be found in our FMOD Unity docs on Connecting Using Live Update.

Ok so this is a simplified version of my code (the actual code is in Unity ECS so it’s a bit different, but the FMOD part is the same):

public class NearbyCarsEngineAudioPlayer : MonoBehaviour
    [SerializeField] private EventReference _carEngineSound;
    private List<Vector3> _nearbyCarsPosition = new List<Vector3>();

    void Update()
        foreach(var nearbyCar in _nearbyCarsPosition)
            RuntimeManager.PlayOneShot(_carEngineSound, nearbyCar);

    void FixedUpdate()
        // Here there is some physics overlap sphere logic to get only the 5 nearest cars' position that are near enough

Ok thanks, I tried it and it seemed to have solved this issue!
But it still seems like there’s a general stuttering in the audio (even with other SFX), don’t know why.

I may also need to try to improve the engine’s sound audio because it doesn’t sound that good with a combination of 5 of them running all at once, but that’s another thing.

Ok I’ll see with the FMOD’s profiler what is going on

I think I’ve majorly solved the issue (camera shake was also moving the camera and there were some weird artifacts), now it’s mostly a problem of the cars engines’ sound overlapping which I don’t like, probably I need better SFX or add some effects to improve it

It good to hear that you’ve mostly solved the issue.

As far as overlapping sounds go, you may wish to explicitly set the 3D attributes of each event instance to the corresponding nearby cars instead of simply playing them as a oneshot. This will apply spatialization and doppler over the lifetime of the event, instead of just based on the initial position. Using a multi-instrument with a variety of different car engine sounds can also help.

Since your code snippet is not exactly what you’ve implemented with Unity ECS, it’s impossible for me to tell for sure that this is the case, but your code appears to be playing a new oneshot event every single update for each car. Creating a large amount of events extremely frequently can also cause stuttering, though typically this is accompanied by warnings for buffer starvation in the mixer thread and command buffer. This could also contribute towards your overlapping audio .If you are running into these warnings, you may wish to do something like remove nearby cars from the _nearbyCarPosition list after creating an event to ensure you’re only playing a single event for a single car.