Incorrect click zone of Buttons ?

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().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

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.
6 Likes

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.

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.

28 Likes

Add also

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.

2 Likes

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 :slight_smile:

5 Likes

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 150150" why i have to click upper zone of button? – According to unity "this button size is 250250” because there little part of this image that user cant see).

I know i tell so bad but hope it is useful for you…

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.

1 Like

Thanks A LOT!!! One more idiot over here, had the same problem. Thank you once again!

1 Like

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.

2 Likes

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.

This helped me, thankyou!

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.

Same here xd thanks man

4 years passed, and there is still a idiot like me. Thanks a lot!!! lol.

Thank you! Thank you!

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

Wow yep. Here’s another idiot checking in

1 Like

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.

1 Like