I'm having trouble keeping the saved sound values.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;

public class Volumen : MonoBehaviour
{
    [SerializeField] private AudioMixer myMixer;
    [SerializeField] private Slider sliderSFX;
    [SerializeField] private Slider sliderBGM;
    [SerializeField] private Image imagenMuteBGM;
    [SerializeField] private Image imagenMuteSFX;
    [SerializeField] private Image imagenLowVolumeSFX;
    [SerializeField] private Image imagenNormalVolumeSFX;
    [SerializeField] private Image imagenLowVolumeBGM;
    [SerializeField] private Image imagenNormalVolumeBGM;

    private void Awake()
    {
        if (PlayerPrefs.HasKey("SFX"))
        {
            LoadSFXVolumen();
        }
        else
        {
            SetSFXVolume();
        }

        if (PlayerPrefs.HasKey("BGM"))
        {
            LoadBGMVolume();
        }
        else
        {
            SetBGMVolume();
        }
        EstoyMuted();
    }

    public void SetSFXVolume()
    {
        float volumeSFX = sliderSFX.value;
        myMixer.SetFloat("SFX", Mathf.Log10(volumeSFX) * 20);
        PlayerPrefs.SetFloat("SFX", sliderSFX.value);
        EstoyMuted();
        PlayerPrefs.Save();
    }

    public void SetBGMVolume()
    {
        float volumeBGM = sliderBGM.value;
        myMixer.SetFloat("BGM", Mathf.Log10(volumeBGM) * 20);
        PlayerPrefs.SetFloat("BGM", sliderBGM.value);
        PlayerPrefs.Save();
        EstoyMuted();
    }

    private void LoadSFXVolumen()
    {
        sliderSFX.value = PlayerPrefs.GetFloat("SFX");
        SetSFXVolume();
    }

    private void LoadBGMVolume()
    {
        sliderBGM.value = PlayerPrefs.GetFloat("BGM");
        SetBGMVolume();
    }

    public void EstoyMuted()
    {
        myMixer.GetFloat("SFX", out float volumeSFX);
        myMixer.GetFloat("BGM", out float volumeBGM);

        imagenMuteSFX.enabled = false;
        imagenLowVolumeSFX.enabled = false;
        imagenNormalVolumeSFX.enabled = false;

        if (volumeSFX <= -80f)
        {
            imagenMuteSFX.enabled = true;
        }
        else if (volumeSFX <= -6f)
        {
            imagenLowVolumeSFX.enabled = true;
        }
        else
        {
            imagenNormalVolumeSFX.enabled = true;
        }

        imagenMuteBGM.enabled = false;
        imagenLowVolumeBGM.enabled = false;
        imagenNormalVolumeBGM.enabled = false;

        if (volumeBGM <= -80f)
        {
            imagenMuteBGM.enabled = true;
        }
        else if (volumeBGM <= -6f)
        {
            imagenLowVolumeBGM.enabled = true;
        }
        else
        {
            imagenNormalVolumeBGM.enabled = true;
        }
    }


}

I’ve been trying for a while, but I can’t find the error. I managed to make the graphics options work, etc. But sound is the only one that doesn’t save the values for me.

Your prefs are saved in those SetXXXVolume methods, but when are you calling them? I see you’re calling them in the Load methods (can’t see why, by the way), and those are called on Awake().

I suppose you want to save your player’s volume choices at some point? Like triggered by the volume slider change? Or on Application.exit?

Yes, that’s the important bit that is missing. He might be calling them from UI callbacks which is what I would guess. However the question is if those has been setup correctly. Some Debug.Logs might shed some light onto those issues. However an actual explanation how it is supposed to work would be great. That should have been part of the question.

If I want to constantly save the settings while the player interacts with the Slider.
9136786--1268923--upload_2023-7-10_14-31-39.png
That is a slider that calls one of the Set functions every time it interacts with it, and I want it to constantly update the PlayerPrefs for SFX. Then, when I re-enter the game, it should load those saved sound PlayerPrefs.

Are you sure you actually linked the “correct” object in that UnityEvent? Keep in mind that linking a prefab is possible but would not do what you want. You can actually call methods on prefabs. Make sure your slider event is actually linked to the actual instance in the scene. You can simply click on the ObjectField and Unity will highlight the linked object.

As I said above, try adding a Debug.Log line like this to your set method:

Debug.Log("SetSFXVolume start", gameObject);

Place that code at the very top of the method and this one at the bottom of the same method

Debug.Log("SetSFXVolume new value: " + volumeSFX, gameObject);

You can click on the message in the console to see on which object this code run on (thanks to the second argument). I recommend two logs in case there’s an error in between.

I just solved it, thanks a lot for the help.