Hit result under cursor while dragging widgets

It’s complicated, sort of.

As soon as I start the drag operation
I stop receiving information about
objects under the cursor - the
operation always returns false.

That’s pretty normal, the Player Controller does not receive mouse input during drag operation. The widgets take over.


The goal:

Have the widget send the screen location to the player controller which can then line trace for objects in world space. Essentially, you want to drag a widget and have the cursor react to world space, too.


The method:

  • in the Player Controller (PC) create a custom event with a 2d vector input - this is how the PC is going to receive the data
  • in the content browser create a custom Drag & Drop Operation
  • in that operation override onDragged - it reports the mouse screen location during drag
  • you can’t cast to the player controller from here, though (!) so you’ll need onDragged to call an event dispatcher, broadcasting a 2d vector with the mouse coords
  • when you detect dragging, in onDraggedDetected, rather than creating a standard operation, create a custom one mentioned in the beginning, and dynamically bind its dispatcher to the event in the PC (step 1)
  • at this point the PC will be receiving screen coords, convert Absolute to Viewport to get window’s local space
  • now Convert Screen Location To World Space - this will give you world location and direction which you can use to trace for objects

I double checked the names of the nodes but I really do hope I did not skip any of the steps. Do tell how it goes.

4 Likes