How to Detect Mouse within Mask Image?

I would like to be able to detect whether my mouse is within the mask image.

I know how to detect whether the mouse is within the RectTransform, and it seems that’s what all the events are doing. Very unsure how to limit this to only the viewable section of the mask image. Obviously, the mask image is not a rectangular shape. I could probably do some fancy math, but I figure there has to be a built-in way for this work, since the scroll rect probably implements this?

I thought about raycast. Maybe it would work, but there has be something better I hope?

Thanks.

Raycasts are exactly how the current EventSystem and event handlers work, however at present the (IsPointerOverGameObject) EventSystem and Input handlers only work with GO Bounds (checking for the last OnPointerEnter event and not mask.
So to implement this you would either need to write your own extension to the EventSystem, or simply write a raycast test (based on when IsPointerOverGameObject is true) to further check a mask image on a GO.

My solution was to create a 2D collider on an object and raycast for it within the UI layer when I already knew I was within the gameobject using the normal event system. Everything else I was trying was always checking the gameobject bounds.

Would be nice if there was a way to easily check whether a point is within a mask texture or not. Ah well, my solution works for simple texture shapes (circle in my case.)

Thanks!

There are also the Physics and Physics2D raycasters instead of the default one. Just add it to the Canvas to enable it.