Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Canvas button not working

I added a canvas component to one of my images to override default layer order sorting. Turns out the button controls on that panel have stopped working?

Has anyone any idea about this in Unity? I am using unity 5.5.2.

like image 555
Jajan Avatar asked Oct 20 '17 13:10

Jajan


1 Answers

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 buttons appear next to the field pointerEnter

EventSystem

If you can't see it, here are 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 RaycastTarget)

Raycast target

  1. Make sure you have an EventSystem in your scene
  2. Make sure you have a callback attached to your buttons so as to trigger your functions
  3. Make sure you don't have any CanvasGroup with BlocksRaycast or Interactable set to false
  4. Make sure you have a GraphicRaycaster attached on a gameobject (on the Canvas usually)
like image 59
Hellium Avatar answered Oct 06 '22 23:10

Hellium