Hi there!
I’ll try to explain my issue as simple as possible. I’m working on an Editor UI tool that creates pretty complex controls for managed references. For example, the custom MyControl:
public class MyControl : VisualElement
{
public MyControl(SerializedProperty property)
{
// bunch of initialization
this.TrackPropertyValue(property, this.OnUpdateTrackedProperty);
}
private void OnUpdateTrackedProperty(SerializedProperty serializedProperty)
{
// Refresh UI because something has changed, like an Undo
}
}
However because I have lots of custom controls, every time the Inspector needs to be refreshed, it takes a while to create all the new visual elements.
The documentation also recommends pooling for reuse visual elements, using the AttachToPanelEvent
and DetachFromPanelEvent
.
However if I do this, visual elements that have been recycled will call the OnUpdateTrackedProperty
on both when the previous serialized property changes, and the new one (and this is exacerbated the more you reuse pooled elements).
So my question is: Should I avoid using TrackPropertyValue
? I’m not sure why there isn’t an UntrackPropertyValue
. This would solve the problem, but maybe I’m not understanding how it works?
Speaking about inner workings, is it safe to use TrackPropertyValue
, or is it something that hooks into an internal update and constantly checks if the serialized property has changed?
If someone sheds some light on this, I’ll buy the first round of beers!