Search Unity

Transform/scale raycast positions of UI elements?

Discussion in 'UGUI & TextMesh Pro' started by Zebbi, Dec 28, 2018.

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Is it possible to transform the position or scale of the raycast elements of UI colliders? I'm scaling my camera viewport which changes the appearance of an internal rendertexture, but not the physical position of the positioning of the button colliders, so when the mouse hovers over them, it is offset.
    raycasts for button highlights:


    and raycast clicks:


    Is there anyway of scaling these so they are positioned correctly?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Scale the mouse position, should just work then. Might require a small mod to any raycast code. You then scale the x,y position of the input before raycast, and this will not require collider changes if I understand.

    Add some debug draw so you can see the "scaled" mouse xy position relative to the unscaled colliders while getting the code right.

    Since the only change is a perceptual change to the x and y dimensions of the texture, you logically only need to scale input position before raycast in a complimentary way to offset (internally).
     
    Zebbi likes this.
  3. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Thanks! This is what I've been hoping to do, but I haven't yet found a way of scaling the position before the raycast. I understand the new inputOveride can be used, but I'm yet to understand exactly how?
     
  4. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I'd love to do this, I just don't know the code to use to scale the mouse position.
     
  5. falkenbrew

    falkenbrew

    Joined:
    Apr 21, 2020
    Posts:
    146
    Did you ever find a solution to this? I need to fix the mouse position before raycast, as I am using a second display that is not in fullscreen. This is not handled correctly by Unity (as it's not intended to be used like this).