Unity 2020.3.0f , UIToolkit preview 14
If you register callbacks to AttachToPanel / DetachFromPanel in a VisualElement, you will receive several calls to those callbacks on destruction
public MyVisualElement()
: base()
{
RegisterCallback<AttachToPanelEvent>((_) => Debug.Log("attach"));
RegisterCallback<DetachFromPanelEvent>((_) => Debug.Log("detach"));
}
If you destroy the gameobject that the UIDocument is on you will get the following callbacks for each element:
- Detach
- Attach
- Detach
- Attach
- Detach
This does not seem sensible, especially as hierarchy changes are expected to be expensive