- Home /
UI Button not working
It seems strange, but I've rechecked this lots of times.
I have multiple buttons in my scene that are hidden and interactable is set to false until I change these two things by script. All buttons work fine except for one. I've tried rebuilding the button from another one that was working and just changing graphics and OnClick(). Still, this button doesn't work.
Both buttons are definitely called by the script, because the buttons show up right on time and the other button works. Also, I use sprite swap as button animation (should be visible if anything happens; other one is showing a change caused by hovering with the mouse).
What could I be missing?
Thanks a lot.
EDIT: I am using the most recent version of Unity on OS X (Unity 5.3.3), but the error occured before. It also happens in the built version.
What exactly is the problem? Are you getting any errors? Is interactable enabled?
No errors, interactable is enabled.
I just seems like this one button doesn't receive any input. So no transitions (on hover/click) and none of the actions in the OnClick() component are getting executed on pressing the button.
Answer by phil_me_up · Feb 29, 2016 at 08:15 PM
In your scene you should find you have an 'EventSystem' object. Whilst playing the game, inspect this object and towards the bottom of the inspector you will see some debug information, which includes what the mouse is interacting with at any time. Hover over the problematic button and try clicking it. Is it actually trying to click something else (i.e. is some other component blocking the input?)
I have an EventSystem and I used inspector and debug console to check the button. (Button is - except for his graphic attributes and OnClick() methods - identical to a working button).
I've tried hiding all other UI objects to see if there is something blocking it, but it didn't occur to me to check the ones beneath it in the hirarchy. Due to the nature of Unity drawing the upper ones first, the ones below are rendered above. I feel a little stupid for disregarding this detail of Unity.
Thanks
Answer by Miyed · Oct 23, 2020 at 06:24 AM
I know this doesn't directly answer your question, but in case it helps others in the future.
In my case, I had the following structure setup in the Hierarchy: Canvas->Panel->Button and for some reason, the canvas gameobject was missing a Graphic Raycaster component. Therefore my button (and other UI children of the canvas) were un-clickable.
Your answer
Follow this Question
Related Questions
How to detect interactable state change in selectable objects (Buttons, etc.) 3 Answers
Calling preset Button OnClick events from another script 3 Answers
button.onClick.AddListener(method); NOT Working 1 Answer
Button.onClick.AddListener(() => Attack()); isn't running function math correctly 1 Answer