[UMG] Raycast into world at a different location

Hi everyone,

I have more of a conceptual question. I already have this somehow working but I don’t like my solution at all.

I have UMG window with one widget acting as a “window into 3d world”. It’s using material created by a SceneCaptureComponent2D which is located elsewhere in a Persistent level (it’s a box with a light and items are spawned there - I will refer to this as a CUBE).

My goal is to actively search with mouse for active regions. So as you move the mouse over this UMG widget, a Raycast should be done according to position of a mouse cursor against this widget

My dirty way is to recalculate mouse position in respect to widget position and scale it according to CUBE size so basically it’s each pixel I move the mouse equals to proportional aspect of the cube. I then displace the original vector in relation to the inventory cube size / center and fire a raycast.

While it somehow works, it’s not precise and also I feel this is not a proper way how to do it.

I was playing around with screen-to-world conversions but it’s not probably what I need.

So if anyone has a better way how to do this, I would be really happy.

Thank you!

Have you found a better solution for this?