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:
slider.RegisterValueChangedCallback(evt =>
{
float value = (float)Math.Round(Mathf.Max(0, evt.newValue), 2);
Time.timeScale = value;
timeField.SetValueWithoutNotify(value);
});
This works correctly. The timeField (FloatField) is updated without broadcasting its own value changed event.
However, the other way around it doesn’t work:
timeField.RegisterValueChangedCallback(evt =>
{
float value = (float)Math.Round(Mathf.Max(0, evt.newValue), 2);
Time.timeScale = value;
// Doesn't change the slider.
slider.SetValueWithoutNotify(value);
//slider.value = value; // Only this works
});
I also tested that setting slider.value = someValue in fact triggers a new ValueChanged event.
Are sliders special or is this a bug?