Why is DataBinding with BindingUpdateTrigger.OnSourceChanged still triggered every frame in Unity? I am binding an integer variable, and the Binding still triggers even if the value remains unchanged.
I believe BindingUpdateTrigger.OnSourceChanged
needs to be used alongside either the IDataSourceViewHashProvider
or INotifyBindablePropertyChanged
interfaces. At least, that’s the only situation where it’s worked correctly for me.
Refer to here for more information on how to use them: Unity - Manual: Define a data source for runtime binding
Hello,
I asked this question because I need to bind the same information to different places. Creating a universal DataBinding
(as I showed you some time ago in our personal correspondence) doesn’t work due to differing propertyPath
values. As a result, I considered using OnSourceChanged
, but updating the interface every frame in Unity seems resource-intensive, especially when dealing with large-scale data redraws.
In the documentation, I saw how to add IDataSourceViewHashProvider
or INotifyBindablePropertyChanged
to a DataSource
, but I don’t see how to use these functions afterward. Could you share a real example from your side?
Thank you!
If you implement them correctly then you don’t need to do anything else. They get used on Unity’s side of things to manage the updating of bindings.
@spiney199 is correct, you need to implement at least one of the change tracking interfaces in order for OnSourceChanged
to be useful.
We do not keep track of the previously bound values to compare them with the current values and rely entirely on instrumentation to inform us of changes. This is done because keeping previously bound values and comparing them with current values to decide if we should update the binding or not would take more time than simply updating the binding directly in a lot of cases.
Ok, thanks, will try
@spiney199 @martinpa_unity
I have written a separate post describing my issues: https://discussions.unity.com/t/help-me-with-databinding/1591657. Please help me there.