Search Issue Tracker
By Design
Votes
0
Found in [Package]
built-in
Issue ID
1410854
Regression
No
MouseLeaveEvent is not triggered when destroying target
How to reproduce:
1. Open the attached project "My project.zip"
2. Enter Play Mode
3. Click the "test" button at the top of the Game view window
4. Click the "Close" button
Expected results: Tooltip is not visible
Actual results: Tooltip is visible
Reproducible with: 1.0.0-preview.17, 1.0.0-preview.18 (2020.3.32f1), 2021.2.17f1, 2022.1.0b13, 2022.2.0a8
Could not test with: 2019.4.37f1 (UI Toolkit unavailable)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- GPU utilization increases by 20% on Meta Quest headsets when Render Graph is enabled on 6000.0.16f1 and higher
- Value on Slider (Int) control in UI Builder displays as default when saving UI Document
- Color mismatch in UI Builders Library panel when the Editors theme is set to Light Mode
- [Android ] "AndroidJNI.ToBooleanArray" returns a random non-zero value instead of "IntPtr.Zero" when the method argument is null
- Non-HDR color picker opens when selecting material color with HDR enabled
Resolution Note:
This is indeed by design. No events are sent to elements that aren't part of a panel, because events are tied to panels (for example there are some differences between how editor panels and runtime panels process their events).
Also, MouseLeaveEvent isn't sent immediately when an element isn't found under the mouse. Instead, it's sent as part of a process of updating the element under the mouse, which happens through an event queue, and the DetachFromPanelEvent is processed earlier, with a higher priority.
We don't want to change the order in which events are processed unless this becomes a real generalized problem that requires a larger redesign. What we recommend is to always consider using RegisterCallback<DetachFromPanelEvent> as an additional entry point for code that react to their elements losing their hover state, or focus state, or pointer capture state, or any other on/off state that usually comes with events for both sides of the change.
It's not impossible that this could change in the future, like MonoBehaviours receiving OnDisable before they have OnDestroy called. Simplifying edge cases in the event system is a goal for the future, but it shouldn't hurt any forward-compatibility to keep a local bool to track the status and react to DetachFromPanelEvent as an additional precaution, and it will work now as well as in the future in any case.