Creating settings of the game

Hello,

I am creating the settings menu for my game and I just implemented 3 methods on my SoundManager, one for changing the master volume, one for the sfx volume and one for the music volume. I have then 3 sliders on my main menu scene and I have properly attached the sliders to the logic of the 3 methods. The sliders go from 0 to 10, so I pass that value to the SoundManager and then just before calling the setVolume function I divide the volume by 10, so the value I will pass to the FMOD setVolume method will be from 0 to 1.
The weird thing is:
If I divide the volume by 10 in the SoundManager script, when I hit the play button the sound is automatically lowered. If I divide the volume by 10 on the settings script and hit Play the sound is as it should. BUT this is all happening WHITHOUT the code being executed. The sliders are on another scene and if I put a Debug into the methods that change the volume, they are not being called. BUT those numbers seem to be affecting FMOD and I don’t know why.

Can someone explain this behaviour to me? Why is FMOD changing the volume parameter without any code being called?

Excuse me if it’s hard to understand but I can’t find other words to exposing the case.

If you are controlling the three volumes (master, sfx, music) via manipulating buses or VCAs then these settings are stored in the FMOD system’s mixer which is why it persists between scenes.

If I’m mistaken, could you please provide the code you are claiming isn’t being called to take a closer look at?

Hello Richard, and thanks for the reply. Here’s the code of the SoundManager. The methods ChangeMasterVolume, ChangeMusicVolume and ChangeSFXVolume are the ones I call from the settings’ slider of my menu. I made a few modifications since the original post, because before I was using “masterBus.setVolume(newVol / 10f);” as my slider goes from 0 to 10, and having that 10f there was modifying the volume of the game even though I was not calling the 3 methods mentioned (note that now I am calling them from LoadSettingsValues as I already integred it with my saving settings, but not on the original post). I even put a Debug.Log on the methods to see if they were being called somehow but the Debug never showed up, but the volume was clearly being affected by the 10f.

Do you recognize some code that could be modifying the bus volume even though I am not calling the 3 mentioned methods?

using UnityEngine;

public class SoundManager : Singleton<SoundManager>
{
    #region Variables
    private FMOD.Studio.Bus FMODBus;

    private FMODUnity.StudioEventEmitter m_FMODEventEmitter;

    private FMOD.Studio.EventInstance dialogueSnapshot;
    #endregion

    #region Unity

    private void Awake()
    {
        GameGrid.soundManager = this;
        FMODBus = FMODUnity.RuntimeManager.GetBus ("bus:/pause");
        m_FMODEventEmitter = GetComponent<FMODUnity.StudioEventEmitter>();
        SubscribeToEvents();        
    }

    private void OnDestroy()
    {
        UnsubscribeToEvents();
    }

    #endregion

    public FMODUnity.StudioEventEmitter GetFMODEventEmitter
    {
        get { return m_FMODEventEmitter; }
    }

    private void SubscribeToEvents()
    {
        EventDispatcher.onGamePausedHandler += PauseSound;
    }

    private void UnsubscribeToEvents()
    {
        EventDispatcher.onGamePausedHandler -= PauseSound;
    }

    public void StopMusic()
    {
        if (m_FMODEventEmitter.IsPlaying())
            m_FMODEventEmitter.Stop();
    }

    public void PlayMusic()
    {
        if (!m_FMODEventEmitter.IsPlaying())
            m_FMODEventEmitter.Play();
    }

    public void PauseSound(bool enabled)
    {
        FMODBus.setPaused(enabled);
    }

    public void StartDialogueSnapshot()
    {
        string snapshotPath = "snapshot:/mix_dialogue";
        
        dialogueSnapshot = FMODUnity.RuntimeManager.CreateInstance(snapshotPath);
        dialogueSnapshot.start();
    }

    public void StopDialogueSnapshot()
    {
        dialogueSnapshot.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
        dialogueSnapshot.release();
    }

    public void LoadSettingsValues(UserSettings settings)
    {
        ChangeMasterVolume(settings.MasterVolume);
        ChangeMusicVolume(settings.MusicVolume);
        ChangeSFXVolume(settings.SoundVolume);
    }

    public void ChangeMasterVolume(float newVol)
    {
        string masterBusString = "bus:/";
        FMOD.Studio.Bus masterBus;
        
        masterBus = FMODUnity.RuntimeManager.GetBus(masterBusString);
        masterBus.setVolume(newVol);
    }

    // Change the volume of the music.
    public void ChangeMusicVolume(float newVol)
    {
        string musicBusString = "bus:/pause/music";
        FMOD.Studio.Bus musicBus;
        
        musicBus = FMODUnity.RuntimeManager.GetBus(musicBusString);
        musicBus.setVolume(newVol);
    }

    // Change the volume of the SFX.
    public void ChangeSFXVolume(float newVol)
    {
        string sfxBusString = "bus:/pause/sound";
        FMOD.Studio.Bus sfxBus;
        
        sfxBus = FMODUnity.RuntimeManager.GetBus(sfxBusString);
        sfxBus.setVolume(newVol);
    }

    public void ResumeEverything()
    {

    }

    public void PauseEverything()
    {

    }

    public void PlaySound(string route, Vector3 position, string objectName = "")
    {
        try
        {
            FMOD.Studio.EventInstance instance = FMODUnity.RuntimeManager.CreateInstance(route);

            if (instance.isValid())
            {
                instance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(position));

                instance.start();
                instance.release();
            }

            else
            {
                Debug.LogError("[FMOD] Event not found " + route + " in" + objectName);
            }
        }

        catch
        {
            Debug.LogError("[FMOD] Event not found " + route + " in" + objectName);
        }
        
    }
}

The code itself looks fine, but I’m interesting when LoadSettingsValues gets called. Are you able to attach Visual Studio to Unity and add breakpoints to this function?

Hello!
LoadSettingsValues was not implemented when I wrote the original post. At the moment LoadSettingsValues is called when the game starts, but back then there was noone calling these ChangeMasterVolume, ChangeMusicVolume and ChangeSFXVolume methods as they were being linked to a slider on a separate scene.

I’m a bit confused by what is currently happening and what you are expecting to happen.

Could you comment out these three functions and see if you are still experiencing the same volume issues?