Hi, I am having this weird problems with callbacks.
I am writing some code with UIElements where I am in need of doing things to text when the user changes the value of a TextField - however, it seems the callback is also firing when the label of the textField changes. For my particular case, this is a bit cumbersome, because it breaks things for me. Is there a way to only get the callback when the value changes (not the label), or any way we can discern in the callback, who it is destined for?
_factFilterField.label = "FactFilter";
_factFilterField.RegisterCallback<ChangeEvent<string> >(evt =>
{
Debug.Log($"FactFilter We are called with {evt.newValue}");
UpdateListView();
});
_factFilterField.label = "FactFilter 2";
This code actually prints both FactFilter and FactFilter 2 , which is weird, but I guess can come from not Unregistering the callback. This is though besides the issue I am having - which is, a change in the label text of a textField should not cause a ChangeEvent where it is not possible to know if the label or value was changed.
RegisterValueChangedCallback has the exact same behaviour.
_factFilterField.RegisterValueChangedCallback(evt =>
{
Debug.Log($"FactFilter We are called with {evt.newValue}");
UpdateListView();
});
This is on
2022.2.1f1.112.6257
Revision: 2022.2/release 4fead5835099
I tried looking at the documentation to see what is expected behaviour, but I did not find anything that spelled it out for me. I hope someone on here can help me.