Use looping sounds playback best practice

I have a looping sound of my character swimming/pushing a boulder our sfx designer done the sounds and sent us the BANK, everything is working great but I can’t get my head around how to handle 3D looping sounds.
Reading the StudioEventEmitter I ended up with this code

if (_rigidbody.velocity.magnitude > 0.1f)
                {
                    if (!isPlayingLoopSound)
                    {
                        loopSoundInstance = FMODUnity.RuntimeManager.CreateInstance(waterSwimSound);

                        loopSoundInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
                        FMODUnity.RuntimeManager.AttachInstanceToGameObject(loopSoundInstance, transform);

                        loopSoundInstance.start();
                    }
                }
                else
                {
                    if (isPlayingLoopSound)
                    {
                        loopSoundInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
                        loopSoundInstance.release();
                    }
                }

Except that the sound is not fading on stop this code is working but I feel like I’m not doing it in the right way, I don’t want to create a new instance everytime the character move again and don’t think I should release it everytime character stop while swimming.

Can someone give me an hint about how to handle looping sound playback?

For the sound to fade on stop, the event has to implement a release, or any behavior triggered on stop.
Stopping/releasing the event when the sound should be stopped, and starting another instance when it should be restarted, is a perfectly fine and standard practice.

So I need to ask my sfx designer do add a release?
Also for sound playing I don’t want it to just pop would like to fade in when starting and fade out when stopping.

What is the best practice in this case?

Yes, both cases will be handled by the sound designer within fmod studio. He should add an Attack and Release delay, with the AHDSR modulator, on the master volume of the event.
He may optionally add a randomization on the offset, if you don’t want the loop to always start at the beginning.

1 Like