Raycast doesn't ignore masked part of an image

Hello,

I’m trying to create a clickable angle between two lines. I’m using an image with a circular sprite and I’m radially masking out a part of it depending on the current angle.

The problem is that I can still click on the invisible part.

I can’t find out how to solve this issue. Any help would be much appreciated!

Here’s the code (probably won’t help, but just to be sure):

GameObject angleGraphic = new GameObject("angle", typeof(Image));
            angleGraphic.transform.SetParent(angles, false);
            var imageComponent = angleGraphic.GetComponent<Image>();
            imageComponent.sprite = circleSprite;
            imageComponent.color = color;
            imageComponent.type = Image.Type.Filled;
            imageComponent.fillMethod = Image.FillMethod.Radial360;
            imageComponent.fillClockwise = false;
            imageComponent.fillAmount = angle.Degrees / 360f;

In an attached script, I’m simply implementing the IPointerClickHandler interface.

Thanks in advance!

Found solution! Make the sprite readable and use Image component’s property imageComponent.alphaHitTestMinimumThreshold = 0.95f;
This way, only part of the image with pixels having alpha > 0.95f registers interactions.

Additionally, I have to use my own method and some basic logic to determine if user points over the non-masked part of the image, but this solution is clean enough.