How do I find the rect of a UnityEngine.UI.Graphic object relative to its Canvas?

Should be easy, but I haven’t found a way to do it. I’m working on a virtual reality app, and the Canvas is a child of an in-game object. It does NOT get painted on a screen as it would in a non-vr game.

I’m trying to make the ui elements interact with our own custom mouse-cursor, as well as Vive controllers, and head-mounted cursors such as GearVR. I can raycast and find the cursor location in canvas-local coordinates. However when I try to determine which of the Canvas’ descendant Graphic objects are intersected by the point, I hit a brick wall.

I’ve tried translating the Graphic rect to world coordinates and from there to canvas coordinates, but the Graphic transform.scale reads (incorrectly) as (0, 0, 0), so I can’t determine the scale of the Graphic rect relative to the Canvas.

I’ve also tried computing a Graphic rect relative to it’s parent’s coordinate space, using the RectTransform’s rect, anchorMax, anchorMin, offsetMax and offsetMin fields, and using that to recursively determine the rect relative to the canvas, but the offsetMax and offsetMin appear to contains offsets from the center of the Graphic rect, and NOT from the anchorMin and anchorMax as the documentation states. Once again, I don’t seem to have enough information to sort things out.

I hope very much that I’m missing something obvious. Please let me know if there’s a better way to do this.

Many Thanks,

Patrick Arnesen
AltspaceVR

have you seen Unity - Scripting API: RectTransformUtility last two functions?