Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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

Discussion in 'UI Toolkit' started by Xarbrough, Jul 3, 2019.

  1. Xarbrough


    Dec 11, 2014
    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
    does not change the slider, whereas
    slider.value = 1f

    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. uMathieu


    Unity Technologies

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