- Home /
So my buttons stop working...
Yeah, I know other people had this problem, but none of their answers worked for me... I'm making a text based game, and on the Chapter Select screen, the buttons stopped working after I changed their highlighted color. It did it before when I tried to build the scene before, but that time the buttons stopped working when I changed their position on the screen.
Can anyone help? I've gotta get this scene complete so I can get to work on the actual levels.
Thanks
I attached a picture of the screen, just in case.
If someone gave you an answer that helped and now your code is working, why not accept their answer?
Answer by Hellium · Sep 04, 2017 at 03:43 PM
The easiest way to debug is to :
1. Run the game in the editor, not in full screen (uncheck Maximize On Play
button)
2. Select the EventSystem GameObject of your scene
3. In the inspector, open the Preview Window and make it big enough
4. Move your mouse on your screen, and check if the name of your button (or one of its children) appear next to the field pointerEnter
If you can't see it, possible solutions :
1. Make sure you don't have any UI elements above your button which could block the raycasts
2. Make sure you have enabled raycasting on the images used by your buttons (check box Raycast Target
in the edito)
3. Make sure you have an Event System in your scene and a GraphicRaycaster attached on a gameobject (on the Canvas usually)
4. Make sure your buttons are interactable (checkbox Interactable
in the editor)
5. Make sure you have a callback attached to your buttons so as to trigger your functions
6. If your canvas is set to Screen Space - Camera
or World space
, make sure you have specified a camera
7. If you have rotated / scaled UI elements, the click may not be detected. In this case, uncheck Ignore Reversed Graphics
in the Graphic Raycaster
component of the canvas, or set the rotation correctly of the element and use a rotated / scaled child image (with Raycast target
disabled) in order to have the desired "graphical result"
8. Check if you have a Canvas Group
attached to the object or one of its parent, and make sure the Interactable
and Blocks Raycasts
are both checked.
@Hellium Hey, I'm Late... I Checked The EventSystem, There Is A Panel Before $$anonymous$$y Buttons.. That's Why They Are Not Working... How Do I $$anonymous$$ake The Buttons Before THe Panel?
Either uncheck the Raycast Target
tickbox of the panel or reorganise your hierarchy so that buttons are drawn after your panel.
For example, if you have a hierarchy as follow
GameObject1
└ GameObject2
└ Button 1
└ Button 2
GameObject3
└ Panel
Change the hierarchy like this
GameObject3
└ Panel
GameObject1
└ GameObject2
└ Button 1
└ Button 2
Answer by DiegoperezB · Dec 30, 2020 at 08:17 PM
I know this is already answered but i had another similar problem that i already solved, so i am going to show for someone that may have the same problem.
Problem: In one of my projects i had a UI with buttons that was enabled and visible all the time. It worked well except for when my character started walking, then the button didn't work. Solution: I realize it was a problem with the pointerEnter, i tried many solutions that didn't work but in the end the solution was to change the Canvas render mode to 'Screen Space - overlay' i am not sure why but it was fixed then.