[Solved] UI Button not working at all

My button won’t even highlight on mouse over.

I have an EventSystem.
Tried with the EventSystem option Force Module Active.
I have only one Canvas.
The Canvas has a Graphic Raycaster component.
Canvas Render Mode is set to Screen Space - Overlay, also tried the other two with the camera, didn’t work.
The button is a child object of the Canvas.
The button is marked as interactable and calls a function from a script.
There are no other HUD objects that are at the same place as the button.
I’ve added using UnityEngine.EventSystem; to my script.
Tried putting the button on different places in the hierarchy.
Tried playing the game and restarting Unity a couple of times.

There are a few more things I’ve tried for sure, can’t remember everything at the moment… getting desperate already.

9 Likes

don’t the raycasters go on the camera? not sure if that’s an issue or you just need one in the scene…

3 Likes

Hmm not sure, tried it now, if I add a Graphic Raycaster to the Camera component, it adds a Canvas component too, which should be on the Canvas GameObject. Also tried variations with this, changing the camera render mode with the Raycaster on Camera, no success once again…

What version of Unity, what OS are you building for? It often helps to narrow down the problem by stripping away everything then slowly adding things back. I would create a new empty test project. Add UI Button to the scene, it should automatically add a Canvas and an Event System. Then Create an Empty Game Object that is a root object in the hierarchy. Create a Script with one Public function called TestButton that just calls Debug.Log(“I’m pressed”). Attach it to your GameObject, then attach the Button’s OnClick to that Function in the editor. Play and press the button and see if you get the Debug Log in the console. I suspect you will.

I’d do all the above with the default settings Unity has for everything. Then change the settings to what your project has. Possibly adding more items and objects from your scene until it stops working.

4 Likes

After a long time I managed to find the problem, although it was already wrong in the tutorials default settings.

If anyone else will have a similar problem, select your Canvas GameObject and look at it’s components. I had the following:
Canvas, Canvas Scaler, Graphic Raycaster, Canvas Group etc…
Select the Canvas Group component and check the boxes of “Interactable” and “Block Raycasts”. It works like a charm now. Thanks everyone for your effort.

24 Likes

Hi to all,

I am using Unity 5.5.2 Personal and I’ve recently created a start up scene for my project. I’ve just put 2 UI buttons for which Unity has created a Canvas GameObject. The UI buttons are child of this Canvas.

What I’ve noticed is that by default the Canvas GameObject was created without the raycaster and group components (I don’t remember if there was a scaler component at the initiation of the GameObject).

The solution for me was to add the 2 missing raycaster and group components with their default values (the 2 checkboxes that Sargaxon mentioned above).

Maybe my fault was that I’ve initially created a UI Image and a UI Text object making Unity to create the Canvas without these components. I really don’t know.

1 Like

I had this problem too, I solved my issue by enabling the Raycast Target check box in Image(Script) (button’s Inspector)

5 Likes

I had this same problem though it was none of the above, i fixed mine cause i had a compile error not haveing horizontal and verticle in the inputs…

Good work! accidentally deleting a component and not knowing which one it was, caused the program to lock up its visual clickable functions. and re adding the component fixes it (Graphic Raycaster) thanks.

5 Likes

So, I had everything working fine. I had my Title menu and game over menu working, but only after I tried to add a pause menu in it, it made only the buttons in the scene I tried to put the pause in stop working. The Title menu works fine, but it doesn’t have a event system or canvas group. I tried copying all the components from the Title menu into that game scene but then they stopped working.

///UPDATE///
After copying the title screen components into the game scene, even though I never altered the title components in the title screen (I just ctrl+c and ctrl+v the canvas into my game scene) they also stopped working. So now no buttons I use work. I have no clue whats wrong, because I didn’t change anything, they just stopped working, and I made sure not to save, so I could go back and hard reset to my last save just in case, but after closing and reopening the project, none of the buttons work, even though Im opening from a file where they still worked.

Me too ! Can you help us, and I want to do a restart button who restart the scene, what is the code for that please ?

Same problem for me, as soon as I duplicate a button, all of the others buttons inside my Canvas stopped working… Does anyone have an idea to fix this?

It’s pretty annoying since I have to re-create all the buttons any time I want to add another one.

2 Likes

Do you have your eventsystem, me I deleted it and that doesn’t work… I create a new eventsystem and now all work !

44 Likes

HI,

check your event system item in the editor hierarchy, inside some check boxes are disabled after duplicating an button (thats was the problem at my side).

17 Likes

I have this problem, how i can adjust it?

Good sir or madam! I could give you a kiss… You fixed a lot of my issues!!! Thanks!

1 Like

spent a good 20 minutes running through all the possibilities just to find that i had a 1000 by 1000 clear text object on the top layer that was blocking my button

6 Likes

I literally have the same exact problem with my game. Someone please help

Same problem with buttons , it stopped responding.