I had an issue yesterday where I couldn’t get the mouse events to register behind a certain UI element. It was weird because it had been working the day before. Then I came to realize I had reset the USS style that had been controlling it because I decided it would be better to set that via C# code. However, it does not appear to be having any effect.
To be clear, I can successfully allow the mouse to be ignored by UI elements if I set their style sheet via the UI Builder. But when I set that same value in C# code with something like ‘CursorRoot.pickingMode = PickingMode.Ignore;’ it appears to have no effect whatsoever and the UI element still intercepts all mouse actions. Is this a bug?
I’m having the same issue, it seems like pickingMode is not getting applied when set through code. On the other hand, setting other properties like focusable on the same element work fine through code.
Note also that pickingMode only applies to the element it’s being set on, and not its children.
If you want to prevent pointer events on children, you can register a callback on the PointerDownEvent/PointerMoveEvent/PointerUpEvent on TrickleDown and call evt.StopPropagation().
You can report the issue with a small repro project using Help → Report a Bug… It might be a problem with only older versions, but we’ll be able to do a full check that way.
Did this get reported? I’m having the same problem (well, a variant of it) in 2021.3 LTS. I have a dragged element that has children in it (basically an “item” with a “stack size” imposed on it). I can’t stop propagation of the events because I “do” need things under the dragged item to get the clicks. Setting PickingMode=Ignore on the item works if it has no children. Recursively setting PickingMode=ignore on all the children works sometimes, not others, and seems clumsy in any case.
It also seems that the very existence of children makes this not work (sometimes). The mouse (up, in my case) event doesn’t even have to be over one of the children for it to get eaten.
The above messages imply that you can set PickingMode through USS rather than code, and it’ll work. What property is that? I’m not seeing it listed on the USS properties list page.
[Edited later: It’s not USS; it can be set via UIBuilder as an XML attribute on the actual object in UXML, which doesn’t help me, since my objects are created dynamically based on the items.]
Yeah, that’s what I found, too. It’s an attribute on the object, though, which means the entire object needs to be created from UXML, not just styled with USS.