Search Unity

Incorrect click zone of Buttons ?

Discussion in 'UGUI & TextMesh Pro' started by Kazs99, Oct 23, 2014.

  1. Kazs99

    Kazs99

    Joined:
    Jan 25, 2013
    Posts:
    16
    Hello,

    I work with new GUI for about 3 weeks, all is fine except one bug.

    When I launch, I cannot click easyly on Buttons :
    I must click in specific zone of button to have click. (it's different for each Buttons)

    I have a Canvas with myltiples screens (panel) as children.
    All children are desactivated at start with a

    for (int i = 0; i < transform.childCount; i++)
    {
    Transform child = transform.GetChild(i);
    child.GetComponent<RectTransform>().localPosition = Vector3.zero;
    child.gameObject.SetActive(false);
    }

    I activate/desactivate children to set the good state of my game.

    Some Buttons works well others doesn't works at all...

    The same problem is present on TextFields...

    Thanks
     
    Last edited: Oct 23, 2014
  2. Trav3l3r

    Trav3l3r

    Joined:
    Sep 16, 2014
    Posts:
    60
    We've had this issue too on several occasions in one of our projects. Some things we noticed
    - the way you order objects in the hierarchy is very important. Text elements on top of buttons is a no-no (even when there is no visible text on top of the button)
    - something is definitely going wrong when you have screensize rendertexures in combination with ui elements. They shouldn't interfere with mouse events but they do (ie a text element on a section that is used in as rendertexture can interfere with something that is in normal camera view). Although this can be circumvented by removing the raycast script on the ui element, it seems like an unnecessary step.
     
    woitee, Quiddleoo, Nariomugi and 3 others like this.
  3. Kazs99

    Kazs99

    Joined:
    Jan 25, 2013
    Posts:
    16
    Thanks for your reply.

    I have more information about my bug:

    If I unactive UI GameObject in code, I have the problem
    If I unactive UI GameObject in the editor before launching, all works fine.

    It's seems that there is some bug on ingame SetActive(false) on GUI Button.
     
  4. playbatu

    playbatu

    Joined:
    Feb 2, 2016
    Posts:
    1
    for idiots like me. if you have a text as a child for a button. And your text width is huge while your visible text is small. You should close raycast target for your text or adjust your text area properly. Empty areas of your text element will interfere with other buttons based on their hierarchy. lol.
     
  5. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    Add also
    Code (CSharp):
    1. child.GetComponent<RectTransform>().localScale = Vector3.one;
    Actually scale all UI objects to 1. Set their size by changing borders, bigger width, larger font etc.

    I had this issue on Android that if i scale anything, you can't touch buttons.
     
    pajowa15 and Xavier78 like this.
  6. LeRan

    LeRan

    Joined:
    Nov 24, 2015
    Posts:
    118
    Thank you comrade, you saved me lots of trouble finding what was wrong with my buttons. Someday idiots will unite, and the world will tremble :)
     
    mopthrow, Henry_Xie, Lisunity and 2 others like this.
  7. broozkan_

    broozkan_

    Joined:
    Nov 12, 2016
    Posts:
    1
    hi everyone, i have same issue about few minutes ago. I solved the problem with checking image size. i mean i thought i could crop image clearly and i recognize i couldn't. So unity thought this image size is bigger than user's vision. So it was saying the click zone is large. (Ex: According to my opininon "my button size is 150*150" why i have to click upper zone of button? -- According to unity "this button size is 250*250" because there little part of this image that user cant see).

    I know i tell so bad but hope it is useful for you...
     
  8. aseceans

    aseceans

    Joined:
    Sep 9, 2017
    Posts:
    2
    I solved this problem by removing Raw Images. A raw image was overlapping an area on my button and it made that area un-clickable, regardless of whether the button was above the raw image in the hierarchy. For some reason raw images and buttons don't play nice so I switched my raw images to Sprites.
     
  9. karayeva

    karayeva

    Joined:
    Feb 19, 2013
    Posts:
    11
    Thanks A LOT!!! One more idiot over here, had the same problem. Thank you once again!
     
    danosono likes this.
  10. Swegfan

    Swegfan

    Joined:
    Dec 17, 2016
    Posts:
    1
    Been creeping on forums for far too long just looking for anwers to questions, but for this one i found myself the answer.
    , It's the text on those buttons that caused the issue, It's most likely upscaled and inteferes with it's parent.
     
    AllFlarus and Xavier78 like this.
  11. Xavier78

    Xavier78

    Joined:
    Oct 13, 2013
    Posts:
    41
    Having same issue, it is Textmesh pro. When ever I have a TMP object as a child of a button on a canvas with "Raycast Target = true" if it helps the objects are all children of Horizontal Layout group that are children of a vertical layout group.
     
  12. DarkFlameDX

    DarkFlameDX

    Joined:
    Feb 28, 2015
    Posts:
    3
    +
     
  13. boggyb11

    boggyb11

    Joined:
    Sep 29, 2018
    Posts:
    1
    This helped me, thankyou!
     
  14. austinator222

    austinator222

    Joined:
    Dec 10, 2014
    Posts:
    1
    For anyone that may have this problem in the future and none of these tricks worked... Ask yourself, did you make custom buttons in photoshop or something like a photoshop app. My problem was that my photoshopped image width and height made a square, and I was making rectangular buttons. After I made those rectangular buttons I would just make everything else in the background transparent but unity still counts those transparent pixels as an actual clickable part of the rectangle. So, MAKE SURE TO FILL THE ENTIRE WIDTH AND HEIGHT OF YOUR IMAGE TO THE FULL SIZE OF THE IMAGE WHEN USING PHOTOSHOP (EX: If you're trying to make a rectangular button, make the photoshop image size a rectangle and not a square). So in general, just don't have transparent pixels, it may also mislead a player of your game! Btw, I spent days trying to figure this one out.
     
  15. zokaper55

    zokaper55

    Joined:
    Aug 18, 2019
    Posts:
    1
    Same here xd thanks man
     
  16. Henry_Xie

    Henry_Xie

    Joined:
    May 30, 2020
    Posts:
    5
    4 years passed, and there is still a idiot like me. Thanks a lot!!! lol.
     
  17. NGreiner90

    NGreiner90

    Joined:
    Sep 11, 2015
    Posts:
    1
    Thank you! Thank you!
     
  18. Emperatrixxx

    Emperatrixxx

    Joined:
    Jul 4, 2021
    Posts:
    1
    For idiots like me: double check if the text element that is a child of the button has no EVENT TRIGGERS attached to it, Those prevent the function of the parent from firing.... That's what happened to me at least
     
  19. hockenmaier

    hockenmaier

    Joined:
    May 11, 2016
    Posts:
    11
    Wow yep. Here's another idiot checking in
     
    greysun likes this.
  20. greysun

    greysun

    Joined:
    Feb 23, 2017
    Posts:
    9
    2022 and this answer is still relevant, hours I was trying to figure this out thinking it was something in my code when the text area was just too large.
     
  21. Alex_Gekko

    Alex_Gekko

    Joined:
    Nov 14, 2022
    Posts:
    1
    Hi all. I believe this problem occurs when there is more than one Canvas in the scene, especially if you are using a mixed World Space and Overlay type. Make sure that you place the buttons exactly in the Overlay, and that everything that is in the World Space is either correctly centered relative to the Overlay, or does not have its buttons there.

    It helped me right away. (I advise everyone, before developing a UI, to draw a diagram of the hierarchy and think carefully about what should be located where)