UI Button positioned outside Panel parent not registering click event (Unity 5.3.4)
I have a weird problem with a UI Button:
The UI button is the child of a UI panel. The panel is positioned outside of the screen. The button itself is the only thing visible on screen and therefore positioned outside of its parent panel (and anchored to one corner of the panel). When the button is clicked, the whole panel plus button moves up (on screen) and with another click it moves down (outside of screen, only button visible).
Last time I worked on the project everything worked fine, but today the button does not register a click event anymore. I haven't changed anything since then.
When I move the button object outside the panel in the hierarchy, so that they are not related anymore, it does work again. But I don't get why...because two days ago it did also work when the button was a child to the panel. It has to be a child, so the button will move with the panel and is always relatively positioned to it.
I checked: The code and animations work properly, I have a canvas, an event system and all other buttons work. Also the mentioned button is not covered by anything else and should be the last thing rendered.
Has anyone an idea what the cause of the probleme could be?!
The most likely cause is you have another UI element over the button. If you detach the button I'm betting this moves it lower down in the hierarchy and the bottom of the hierarchy is foremost as far as the UI goes. Try moving the panel with the button attached to the lowest sibling.
That means the lowest UI element for the parent object, so if the parent of the panel is a canvas then any direct child objects of that canvas are the panels siblings so move your button panel to the bottom of that list.
Like wise if you have other siblings of the parent for that panel make the buttons-panels-parent the lowest element for that parent-parent object.
I'm not even sure I understand what I mean with that last bit!
But lower in the hierarchy is more to the front on the UI.
This would be easier with an image but not got access to Unity right now.
Thanks for your answer. I attached two screenshots so you can see what I mean. When I asked the question I already tried that bit out: The panel is the last thing in the hierachry and the button is the last child of the panel. This way it does not register the click. When I move the button outside the panel (e.g. above it), it does register the click successfully.
It's really weird, technically it should work but it doesn't and I'm out of ideas now! :(
First pic = not working | Second one = working
I also tried it now with a completely empty scene with only the (empty) panel and the one button inside the canvas and its still the same. So there is definitely no other object or script interfering.
Answer by CHG_Eve · Jun 09, 2016 at 03:20 PM
Ok, i finally found the problem after reproducing the whole thing in a new project:
I had (for whatever unknown reason) a canvas component on my UI panel that did not serve any purpose. After removing the canvas component everything worked again, even if the button was a child of the panel.