Button Highlighting before mouse cursor is over it?
My buttons clearly have a larger 2dcollider than the actual button, as they highlight well before the mouse hovers over them. This becomes a problem because the last button blocks out the ones next to it if they are too close together. How can I make button 2dcolliders match their sprite size? I am just using the standard UI sprite.
I am using a horizontal layout group component. It appears that the "tolerance" for when mouse is considered over the button is more acute in the horizontal position... ie, when the mouse is one button width away from the actual button (say 64 pixels away from a 64 pixel button), it still highlights and is intractable, but if it is more than say 16 pixels above a 64 pixel button, it will stop interacting.
Answer by xxmariofer · Jan 23, 2019 at 08:52 AM
Easiest approach is make the sprites you are using have no side free space.
I am using the standard UI sprite that comes with Unity called "UIsprite" from Resources/unity_builtin_extra
Not sure if you can force the sprite to expand, i am sure that the reason your button is more accurate in the y than in the x is because your button width is more than his hieght, since the button sprite has the same space in the right and top borders. try removing the sprite from the image and you will see the true size of the button, can you just get that uisprite copy and edit and remove the free borders?
Answer by Ne0mega · Jan 24, 2019 at 03:44 AM
It was the TextMeshPro Text rect. I changed the size of the TextMeshPro Text rect to match the button size (in this case 64 x 64) and viola, button only clickable/highlights when the cursor is over it.
Oh my gosh you saved me. I've been frustrated over my button instances being all wonky for a few days now, and it ended up being the rect transform on the text children in the button hierarchy. THANK YOU.
heh. this place is dead. That was a long time ago.
Unity's UI is trash, BTW, expect more heartache in all you do.
:)
Your answer
