Hello,
I wish to use a UIDocument as a overlay to manage dragged visualElements but once I get those on top of the others, the elements behind the dragged visualElements (on another UIDocument) wont fire MouseOver/MouseEnter events, I tried both with/without trickleDown but I can’t get it to work.
Am I missing something ? Is it not possible ?
Hi, this seems to be because the UIDocument on top is receiving the mouse events. You can set the picking-mode to ignore on the overlay and that should let the events pass.
Is there a way I can get both to trigger events ?
I wish to use the MouseMoveEvent callback on the top layer (dragged elements on the whole screen) but also receive Enter/Leave events on the layer below (actual UI with drop targets).
If you set the picking mode to only the overlay (i.e. the empty/transparent base element that expands to cover the whole game view/screen), but keep your actual Visual Elements with picking mode set to position (the default value), those elements will still get mouse events and the elements in other sort orders that are seen on the empty/transparent areas should get input as well.
Have you tried that?
Here is my setup at the moment :
(Drag layer has one element that entirely cover the screen)
When I click on a draggable element it’s moved to the drag layer.
| If you set the picking mode to only the overlay […] but keep your actual Visual Elements with picking mode set to position
A this point I can’t ignore the drag layer (overlay) as I use its MouseMove event manage the drag. I tried using the event from the draggable element itself but it would bring two major issues : moving too fast allow the mouse to leave the element and no longer register MouseMove events and you could also drag the mouse out of the game window, leaving the element at the border, and re-enter the mouse elsewhere where the element is not, also breaking the drag.
So right now I end up here where I can drag the element around but the drop target behind won’t trigger MouseEnter/MouseLeave semingly because it won’t go past the drag layer
Not 100% sure it’ll work, but set pickingMode to Ignore on the drag layer, then try this
VisualElement myDraggedElement, dragLayerElement, myDropTarget1, myDropTarget2, dropTarget;
// ...
myDraggedElement.RegisterCallback<PointerDownEvent>(e =>
{
dragLayerElement.CapturePointer(e.pointerId);
});
dragLayerElement.RegisterCallback<PointerMoveEvent>(e => Debug.Log("Moving on the drag layer."));
myDropTarget1.RegisterCallback<PointerEnterEvent>(e => dropTarget = myDropTarget1);
myDropTarget1.RegisterCallback<PointerLeaveEvent>(e => dropTarget = null);
myDropTarget2.RegisterCallback<PointerEnterEvent>(e => dropTarget = myDropTarget2);
myDropTarget2.RegisterCallback<PointerLeaveEvent>(e => dropTarget = null);
dragLayerElement.RegisterCallback<PointerUpEvent>(e =>
{
dragLayerElement.ReleasePointer(e.pointerId);
if (dropTarget != null)
Debug.Log("Dropping " + myDraggedElement + " on " + dropTarget);
});
If I’m not mistaken, the CapturePointer will ensure that your dragLayer gets all the pointer events while it’s capturing the pointer, except the PointerEnter/Leave events which aren’t affected by capture.
It work ! Thanks a lot.