Possible to increase size of the rectangular UI hitboxes

I noticed this in the FAQ:

"How do I make UI elements have non-rectangular hitboxes?
Add a component that implements ICanvasRaycastFilter. In your implementation of IsRaycastLocationValid, reject all points that are ‘outside’ your custom hitbox shape. It’s up to you how…"

But what I am currently interested in is simply increasing the size of the rectangular hitboxes without scaling up the sprites itself. Is this possible without having to implement your own methods?

1 Like

This may not suit your needs but I added a button as a sibling to the thing whose hitbox I wanted to increase. Put the button over it and cranked the alpha on the image to 0. Then made the button whatever size I wanted the hitbox to be.

Just put the sprite as a child of the button. They’re all just components like everything else: Duplicate the button, put one as a child of the other, delete the button component from the child and delete the graphic and renderer components from the parent, and make the parent bigger.

2 Likes

Alright, I’ll take a look at it when I get home and see if I can resolve it.

Interestingly, It also works the other way - you can increase hit are of a button by placing a transparent Image as its child. This way you still has a button as “whole” object and it will report correct size for layout properties.


Not sure why it works this way though :slight_smile:

2 Likes