Search Unity

Bug Slider.SetValueWithoutNotify not working - bug or incorrect use?

Discussion in 'UIElements' started by Xarbrough, Jul 3, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    486
    I'm not too familiar with the new UIElements system, so I'm unsure if this is a bug or intended behaviour, but simply using
    slider.SetValueWithoutNotify(1f)
    does not change the slider, whereas
    slider.value = 1f
    works.

    I want to link two controls together (Slider and FloatField) to recreate the regular float field from the IMGUI system. Whenever one of the values changes I want to perform some action and then also update the other control but without triggering the action a second time.

    For the slider I subscribe to the change event like this:

    Code (CSharp):
    1. slider.RegisterValueChangedCallback(evt =>
    2. {
    3.     float value = (float)Math.Round(Mathf.Max(0, evt.newValue), 2);
    4.     Time.timeScale = value;
    5.     timeField.SetValueWithoutNotify(value);
    6. });
    This works correctly. The timeField (FloatField) is updated without broadcasting its own value changed event.

    However, the other way around it doesn't work:

    Code (CSharp):
    1. timeField.RegisterValueChangedCallback(evt =>
    2. {
    3.     float value = (float)Math.Round(Mathf.Max(0, evt.newValue), 2);
    4.     Time.timeScale = value;
    5.     // Doesn't change the slider.
    6.     slider.SetValueWithoutNotify(value);
    7.     //slider.value = value; // Only this works
    8. });
    I also tested that setting slider.value = someValue in fact triggers a new ValueChanged event.

    Are sliders special or is this a bug?
     
  2. UnityMat

    UnityMat

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    26
    It's definitely a bug. Thanks for reporting this!
     
    Xarbrough likes this.