6
votes

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.

2
Adding a canvas to an object can mess up a lot of things. In this case, it's not so much that the button controls have stopped working, but that the mouse clicks are being captured by the top-most parent canvas and not falling through to child canvases. - Draco18s no longer trusts SE

2 Answers

16
votes

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)
5
votes

Turns out I did not know that you have add a Graphic Raycaster component as well. Started taking input after that.

Thanks everyone.