I’m sure this has been asked before, but could not see anything in the search.
Editing here to say that I’m not convinced by some of my original statements in the OP, but the discussion further down feels like it reveals that there is value in some enhancements to the event system to add events that are valuable for runtime UI, but maybe have limited use for Editor UI.
Original Text:
As far as I can tell with VisualElements, there is currently no system equivalent to the Messages that exist for MonoBehaviours (Start, OnEnable, OnDestroy etc.), or the overridable methods that exist for UIBehaviours (OnRectTransformDimensionsChange, etc.). This is probably fine for Editor UI, but is extremely limiting for Runtime UI, and greatly reduces the ability to create modular UI widgets
I would not expect the same events as MonoBehaviours, but absolutely would expect the following kinds of callbacks:
-
Awake / Start / Init - something after the XMLFactory.Init(), so gathering of references to other Visual Elements is possible. This I would consider essential for modularity
-
WillBecomeVisible / Invisible (usage equvalent to OnEnable / OnDisable in monobehaviours), again, pretty valuable for modularity
-
Update - This would be handy, but for retained mode UI, probably not all that sensible, however:
-
PreRepaint - called prior to the document repainting if the element will be redrawn is extremely valuable
-
OnDestroy or OnRemovedFromHierarchy (particularly useful if you use delegate-binding to drive UI as delegates cannot be unbound in destructors)
Some of these might be handled by the EventSystem (adding / removing from panel), though that seems to be very much about Input Handling and Editor Inspectors at the moment. But maybe some more general-purpose utility events could be added?