Slider graphics not updating, value is updating.

Hey guys!
I’m trying to do a slider countdown (5 seconds). I found this thread but I can’t seem to make the algorithm work.
The variable normalizedTime is updating as well as coundtownBarSlider.value. However, the graphics for the slider are not updating, the bar always starts as a random value and stays that way.

IEnumerator countdown(){
        float duration = 5f;
        float normalizedTime = 0f;
        GameObject countdownBarGO = calculusUIPrefab.transform.GetChild(5).gameObject;
        Slider countdownBarSlider = countdownBarGO.GetComponent<Slider>();
        countdownBarSlider.value = 0f;
      
        while(normalizedTime <= 1f){
            countdownBarSlider.value = normalizedTime;
            Debug.Log("Slider: " + countdownBarSlider.value.ToString());
            normalizedTime += Time.deltaTime / duration;
            Debug.Log("Value: " + normalizedTime.ToString());
            yield return null;
        }
    }


Proof that the value of the slider is, in fact, updating.

Might not be the problem, but definitely NEVER do things like line 4 above, going for the 6th child by number! That could change so easily and you would have no idea why stuff stops working.

Instead, when in Unity, act like Unity, and make a public field, drag the slider in:

public Slider TheSlider;

The Slider is a prefab, I spawn it only in certain conditions.
What should I do in this case?

If you’re spawning it, then no worries, just hold a reference to it when instantiating.
For the slider visuals, not sure why it’s not working…the range is set and Whole Numbers isn’t checked?

Tried to set the range, set min and max, nothing worked out :confused:

Can you move the slider manually when you play the game and confirm the values are changing in the Inspector? Comment out any script-based slider value changes.

Yep, I can.
However, the slider value is updated once the execution of the game is paused and then unpaused.
Otherwise, nothing happens.

It’s possible that graphics aren’t updated in a while loop, I seem to remember something along those lines… Try another approach and see.