UI issue: Getting screen coordinates from a World Space object

I’ve been writing scripts for UI objects using a canvas set to Screen space - Overlay. It’s pretty simple to get the side/corner coordinates from all of the (rect)transforms. However, I’m attempting to modify the scripts to also work with canvases set to World Space.

The graphic raycast I’m using seems to work fine. However, I am not sure how to get the screen coordinates for the (rect)transforms.

I’ve read some about “Camera.WorldToScreenPoint,” however, I don’t know how that would tell me where the UI object’s edges are located without me already knowing.

Is there a way for the graphic raycast to tell me how far inside of the object’s borders it is?

Using Screen space - Overlay, I just need to get the position and size of the object, then it’s simple math. But for an object that could be any distance from the camera… or not even on the camera at all… well, that’s where I’m lost.

Thank you!

I don’t know about the UI, but what I know is: if the canvas has a world space position and you get the width into units you can calculate a bordervector. transform.position (of the UI) minus transform.right * (width / 2), would give you a point on the left edge of the canvas. In world space. You could THEN Camera.main.WorldToScreenSpace(leftEdgePoint) to get the pixel coordinates of that point on screen. Then it’s just a small step to the pixel difference of the cursor.