- Home /
UI.Button not working.
I am facing this weird problem with Unity's UI System.
I have a couple of buttons in my canvas, which work just fine. Then I have a Panel whose gameobject I set to Active after I win the level. Its a game win screen. I have a button as the child of this Panel. This button doesn't work at all.
If during runtime, I switch to scene view and move the button outside the canvas boundaries on screen, and then switch to game view and click the button, it works. and if I move it back in canvas boundaries, it doesn't work.
Did anyone face the same issue or have a solution to it?
You might have another panel rendered on top of the button. Upload a screenshot of your hierarchy and we can look that over for any red flags.
check Event System whether exists in current scene or not.
Answer by DimitriUK · Jul 10, 2015 at 11:49 PM
Hey Sumeetkhobare,
I think I had your issue earlier..
I just simply did this:
Click on Canvas.
GameObject >> Create Empty Child
You then drag panel in to that Empty Child.
Click your Empty Child Object and create another Empty Child Object on the Empty Child object called something like Column1, or it's up to you.
Drag your Button in to Column1 and that should keep it all neat and organised.
Let me know if this solution worked.
Thanks for the answer, I will try this. I was thinking about the same.
This is more of a workaround, still sounds like you had a transparent panel rendered over your button. That panel on top of your button would have blocked interaction with it. That's why moving it off the canvas (aka out from under the overlaying panel) would let you interact with it. With the solution mentioned you moved your button onto a new panel rendered on top of the one originally blocking the button interaction.
Best to figure out exactly what you did wrong in order to avoid repeating the mistake.
Well, I thought about that as well. I checked in 3D view, but my button was above the panel.(I tried below as well, in order to try my luck with 'reverse raycasting'). And as my button was the child of my panel, I am assu$$anonymous$$g that button is rendered after the panel.
I don't think the whole z distance thing works for the new UI. You need to pay attention to the sorting order, and things get rendered from top to bottom based on the their position in the hierarchy. So if panel A was on top of panel B in the hierarchy then panel B would get rendered over anything in panel A.
Answer by kojiornk · Aug 28, 2015 at 06:45 AM
Make sure you only have the "Canvas" component attached to the main canvas object, if you have this component attached to a panel or another UI element, buttons inside other UI objects won't work.
Answer by panderson9149 · Oct 14, 2021 at 04:11 AM
I had a similar issue. I solved it by adding a Graphic Raycaster component to the parent game object the button was under.