Unity UI button not reacting to clicks or hovering
Asked Answered
V

13

26

I'm using Unity 3D's new UI system to build a pause menu for my game. Currently I'm trying to have my buttons respond to mouse clicks. Some of my hierarchy is as follows:

Canvas hierarchy

When I click on one of my buttons in-game nothing happens, this includes a lack of button animation that should occur when hovering. My "Main Canvas" gameobject contains the following components:

Canvas components

I have already ensured that my Image component has "Raycast target" checked and that my Button component has "Interactable" checked.

Button

Could this be because my Canvas' render mode is in screen space (camera)? I need the render mode to be set to this because I have 3D models that are added in front of the UI during gameplay.

Things I have already tried / checked:

  • Ensured that an EventSystem was present
  • Checked that another UI element wasn't covering the buttons, preventing a raycast
  • Ensured that the camera rendering the UI is above my main camera that is attached to the player. The rendering UI camera has a layer of 1 while the player camera has a layer of 0.
Valencia answered 25/7, 2016 at 3:47 Comment(9)
What is Menu and What is Menu Items? Are they Buttons too?Boarish
Menu is simply an empty gameobject used to organize "Menu Items" and "Done". "Menu Items" contains a Vertical Layout Group component that organizes the three menu items. Here is an image of the "Menu Items" gameobject: vgy.me/zBKOg1.pngValencia
This would be hard hard to solve without access to your scene. It could be anything blocking the Button. What Unity version is this? Can you upload the scene to some website then link it here....I will take a look myself.Boarish
I'm using Unity 5.4.0b21 which is the beta (not the most recently released beta though.) I had to use because a critical bug was fixed in it. I would be happy to upload the scene but with the assets that are used it would be a multiple gigabyte download. Just uploading the .unity file probably wouldn't give enough information, would it?Valencia
Close Unity, duplicate you project folder. In the duplicated folder, Delete all textures, models, images sound..etc. I don't need them. The only thing I need in the Project is the UI. Also test it and make sure that the problem is still there before uploading.Boarish
I've modified the scene a bit. Now it's stripped down to only the UI, the main camera, and a directional light. There will be some missing scripts in the UI but it is the same as my scene. Thank you so much for your help tonight, I have to go for now but I will be back tomorrow. Here is the link: mega.nz/#!eMBXWY5a!ehTKtmh-_kJYtLNLnN3ePKzyQaensxLj9Orkcx9edykValencia
Also, the scene is located in "Assets > Custom > Scenes"Valencia
Ok. Will take a look.Boarish
I was making a grave mistake: I was using the Old Input EventSystem, even when I had upgraded to the New InputSystem. So, I went into the EventSystem's inspector... and there, I found the update button...Giorgia
B
58

Your EventSystem GameObject is missing the Standalone Input Module Script component.

Select your EventSystem->Add Component ->Standalone Input Module. Done!

The gif below decsribes two ways to do that.

enter image description here

Boarish answered 25/7, 2016 at 7:29 Comment(4)
That was generous of you, Programmer. It is weird that that was missing. All you do, OP, is click "add canvas" and then "add button". don't "fool with" anything and it will all work.Oxygen
@JoeBlow Yeah I know. It is weird that he is missing in the first place. It is usually automatically created when Canvas or any UI component is created.Boarish
Odd, I had that added before and it made no difference. I'll try that out in a few minutes once I'm at my computer. I'll also check out that scaling question @JoeBlow. Thanks!Valencia
Ha! Would you look at that, the buttons are working now. @Boarish I originally had the Standalone Input Module but removed it right before sending this question for testing purposes. I think it might have been the UI scale mode that was messing things up. Regardless, you have been a huge help so thank you so much!Valencia
H
6

If anyone here ever runs into this problem and none of these fixes work, go to Edit > project settings > Input, then in the inspector tab click the little gear icon in the top right corner and click Reset. this should fix all your buttons!

Hydrophone answered 7/11, 2018 at 21:18 Comment(0)
V
5

Ensured that EventSystem component is present in the hierarchy. Without EventSystem unity is not able to track any events that's occurring in the particular scene

Vallecula answered 5/10, 2020 at 12:1 Comment(1)
This. If you copy a Canvas to a new scene, it will not automatically create an EventSystem. So just create an EventSystem: Right Click-> UI -> EventSystemHudnall
K
2

If anyone here ever runs into this problem and none of these fixes work:

Chose your button in Hierarchy -> Find "Canvas" in Inspector -> Delete IT(Remove component)!

Kittle answered 26/12, 2021 at 11:19 Comment(1)
Not just the one on the button, "Canvas" components on game objects in-between the button and the outter-most canvas should also be removed.Hawking
L
2

If you´re using the InputSystemPackage go to Edit > ProjectSettings > Input System Package. And in supported devices make sure there´s a Mouse option, if not, press the + button below and add the mouse device.

Langan answered 23/2, 2022 at 22:2 Comment(0)
B
2

If you are pausing the game by setting the timescale to 0, then no input will work if the update mode of the input system is set to process events in Fixed Update, since the fixed update is not run at zero timescale - you can change the update mode in Edit > ProjectSettings > Input System Package.

Input settings screenshot

1

Bandstand answered 13/8, 2022 at 12:51 Comment(0)
T
2

I had this same problem in Unity v2020.3.24f1, and after trying all suggestions to no avail I noticed in my case the Graphic Ray-casting was un-checked. Just in case somebody tried everything and is still facing this issue, make sure it is ticked in the canvas element!.

enter image description here

Temblor answered 15/8, 2022 at 17:30 Comment(1)
This was it for me as well. It looks like if you right-click and add a canvas it does not come with these components, but if you add a canvas in the Game Object menu bar it adds these for you. My EventSystem was still using the old model (even though I was using the new InputSystem lol) and changing that did not resolve the issue.Stallworth
C
1

Try to change short order in canvas. Maybe the button canvas is blocked by another canvas.

Cortisol answered 24/12, 2021 at 0:26 Comment(0)
D
0

For me it was because the button was covered by other components in the Canvas. I changged put the button in the very front whithin the campus, and it works now

Dulci answered 1/1, 2022 at 11:47 Comment(0)
S
0

Please check for the "EventSystem" to be present in Hierarchy to make button working. refer the attachment for it

refer the attachment for How it looks like

Suppurate answered 28/3, 2022 at 7:30 Comment(0)
L
0

Had a similar issue, my event system already had the Standalone Input Module attached and I apparently followed the warning and replaced it with Input System UI Input Module which broke mouse events. Adding the standalone Input module back isn't enough, the other input module must be disabled or removed. So try using the Standalone Input Module exclusively in your event system.

Leslielesly answered 12/9, 2022 at 15:12 Comment(0)
L
0

Check If there's not any other object that's blocking the raycasts.

Libelous answered 18/6, 2023 at 5:59 Comment(0)
F
0

I had the same problem. The first selected object in the event system was empty. I inserted the canvas object and it worked.

Fetlock answered 15/6, 2024 at 10:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.