Slider position does not update when value is loaded

Hi can’t make this to work:
Basically I am try to change the value of a slider when I load some value that I previously saved. I have tested the data and it works fine when reading it (the value is what is supposed to be) just does not update the position of the slider :frowning: Please help!

    public void Load()
            {
                if (File.Exists(Application.persistentDataPath + "/weatherInfo.dat"))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    FileStream file = File.Open(Application.persistentDataPath + "/weatherInfo.dat", FileMode.Open);

                    WeatherData data = bf.Deserialize(file) as WeatherData;
                    file.Close();

                    DawnDuskSlider.value = data.hours;
                    
                    Debug.Log("data in data is:" + data.hours);
                    Debug.Log("data in slider is:" + DawnDuskSlider.value);
                    
                }
            }

@paganic
I think it is because you close the file and thus lost the data that it was holding temporarily. Try writing it like this instead:

             public void Load()
             {
                 if (File.Exists(Application.persistentDataPath + "/weatherInfo.dat"))
                 {
                     BinaryFormatter bf = new BinaryFormatter();
                     FileStream file = File.Open(Application.persistentDataPath + "/weatherInfo.dat", FileMode.Open);
 
                     WeatherData data = bf.Deserialize(file) as WeatherData;
 
                     DawnDuskSlider.value = data.hours;
                     file.Close();
                  }
             }