problem with changing volume with slider

Hi! i hope this is right place to ask this question!
I made slider that changes sound value and is connected to singleton soundManager
script by onvalueChange(single) property
Problem is i can change volume with it as long as i am on first scene(main menu), but when i leave that scene and return later to change volume i can move slider and slider value changes but volume is not affected.
Any idea what should i look after?
I dont think it will help but here is function i call by onValueChange event,
I will provide more code if needed

 public void setGlazbaLvl(float lvl)
    {
        mixerMaster.SetFloat("musicVol", Mathf.Log10(lvl) * 20);
        PlayerPrefs.SetFloat("musicVol", lvl);
    }

Where’s the code that ultimately changes the volume on the AudioSource? How does that code know to run?

1 Like

here is whole soundManager

public class zvukManager : MonoBehaviour
{
    // Start is called before the first frame update
   public static zvukManager instance;

    public AudioMixer mixerMaster;

    public AudioSource pucanje;
    public AudioSource sudar;
    public AudioSource bgMusic;
    public AudioSource klik;

    // Start is called before the first frame update

    private void Start()
    {
        float ll = PlayerPrefs.GetFloat("gameLvl");
        setGameLvl(ll);

        float mll = PlayerPrefs.GetFloat("musicVol");
        setGlazbaLvl(mll);
    }

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != null )
        {
            Destroy(this.gameObject);

        }
        DontDestroyOnLoad(this);



    }


    public void PlaySingle(AudioClip clip)
    {
        //Set the clip of our efxSource audio source to the clip passed in as a parameter.
       klik.clip = clip;

        //Play the clip.
        klik.PlayOneShot(klik.clip);
    }
   
    public void setGameLvl(float lvl)
    {
        mixerMaster.SetFloat("gameVol", Mathf.Log10(lvl)*20);
        PlayerPrefs.SetFloat("gameVol", lvl);
        PlayerPrefs.SetFloat("gameLvl", lvl);
    }
    public void setGlazbaLvl(float lvl)
    {
        mixerMaster.SetFloat("musicVol", Mathf.Log10(lvl) * 20);
        PlayerPrefs.SetFloat("musicVol", lvl);
    }
    public void startGameLevel()
    {
        float param = PlayerPrefs.GetFloat("gameVol");
        mixerMaster.SetFloat("gameVol", param);
    }
    public void startGlazbaLvl()
    {
        float param = PlayerPrefs.GetFloat("musicVol");
        mixerMaster.SetFloat("musicVol", param);
    }

These images show onvalueComponentFromSlider before and after changing scenes
5855044--622033--Captureprije.PNG 5855044--622036--Captureslider.PNG

I’m guessing you have that pointing to a zvukManager in the same scene? But you have zvukManager set up so that the first one will stick around between scenes, and when you reload the scene, the copy in the newly-loaded scene will see that one already exists and destroy itself. Hence breaking all saved references to it.

Create a new script on your slider, have your slider call that script instead of calling the zvukManager, and then make the function that script use zvukManager.instance to find the correct zvukManager to call.

2 Likes

You solved it! thanks