- Home /
UI Buttons visible but not clickable when using two canvases.
Hi!
I am having trouble with UI buttons, as they are not clickable. I am using Unity 5.6 with TouchScript 9.0 alpha (though I don't suspect TouchScript is the problem).
I have two canvases:
One canvas which has screen space: camera. It contains a sidebar with some items. The reason for it having screen space camera is that that made it possible to drag objects from the sidebar into the 3d-world.
Another canvas which contains the not working buttons. The buttons are created from prefabs when a 3d object is tapped. There are three buttons, two of which are "normal" and another which works as a background button (very big, invisible and created before the other buttons, meaning it should be "behind" them). It is used for destroying the other buttons, "closing" the menu.
The problem is that when these buttons appear, they are not clickable. However, the background button is clickable. I have tried for a while to fix this, but there must be something I am missing. I tried creating another button just to test if there was something wrong with the prefabs, but the same thing happens.
Sidebar canvas:
Button canvas:
I could only add two images, but the buttons are the set as interactable and has non-persistent on-click listener which are added in code when they are created.
Does anyone have any idea of what to do? I am thinking the problem might be due to raycasts, but not entirely sure.
Answer by TheSOULDev · Aug 14, 2017 at 04:29 PM
Remove raycasting from any button that is not supposed to click. Raycast only hits the first target that is supposed to be hit, the others aren't hit. I supposed the buttons you want to be clickable are behind the background button.
Thanks for the answer. However, I want the background button to be clickable, so removing raycasting from it would the best I guess.
But I tried both removing the background button completely and to remove raycasting from it, but the other buttons were still not clickable.
I have also tried creating the buttons either before or after the background button and neither works unfortunately.
Thank you good sir, you helped solve one of my questions. Greatly appreciated!
You solved my problem! Thank you!
I had 2 canvases on my project. Once I closed and reopened the project, the canvas with an Input Text wouldn't work anymore, it wasn't clickable anymore. Removing the Raycast component from both canvases did it for me.
Answer by Cuttlas-U · Aug 14, 2017 at 04:35 PM
hi; make both of your canvases to "space camera" mode , then try to change Order In layer;
Your answer
Follow this Question
Related Questions
Can't interact with buttons in a UI Canvas in World Space Render Mode. 0 Answers
Lags when clicking so many times,Have problem when clicking so many times 1 Answer
How to click on irregular buttons in new ui 4 Answers
How to use two Canvases in Unity 4.7 ? 0 Answers
Holding down UI Button and shooting raycast from touch position doesn't work simultaneously:(( 0 Answers