Search Unity

Possible to increase size of the rectangular UI hitboxes

Discussion in 'UGUI & TextMesh Pro' started by Freaking-Pingo, Sep 4, 2014.

  1. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    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?
     
    rakkarage likes this.
  2. Fenyx

    Fenyx

    Joined:
    Aug 9, 2013
    Posts:
    8
    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.
     
  3. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    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.
     
    superpig and Senshi like this.
  4. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    Alright, I'll take a look at it when I get home and see if I can resolve it.
     
  5. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    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.
    1.png
    Not sure why it works this way though :)
     
    NamasPlumpus and IgorDemchuk like this.