0
\$\begingroup\$

This is probably a quick and easy fix but I can't seem to get it. As the title says I've got UI buttons which appear when my character dies, they used to work just fine but now suddenly when doing a full test through they don't seem to work. I've found similar posts where the solution was to disable / enable raycasts, that didn't help. Another user was missing an input module from the event system, mine seems to be there an in check.

The only significant change that I think will have affected my UI buttons was the addition of a joystick and another UI button, i thought perhaps they are blocking the older buttons but I've disabled the joystick and new button, that didn't help, even tried changing the zaxis, that didn't help too.

I'm honestly not sure how to go about testing something like this.

enter image description here

The UI overlay is my canvas, the GameOver object is disabled on start then enabled when the player dies, showing the Gameover text, Button quit and rety, these are the buttons that no longer work.

enter image description here

My button retry's settings, mostly unchanged honestly.

Thanks

\$\endgroup\$
  • \$\begingroup\$ Does your button's parent canvas have a GraphicRaycaster component? Is GameOverUI.OnRetryClick() non-empty? \$\endgroup\$ – Draco18s Jan 8 at 18:36
  • \$\begingroup\$ @Draco18s The parent doesn't have a GraphicRaycaster and OnRetryClick isn't an empty method, if that's what you meant. \$\endgroup\$ – Demonic218 Jan 8 at 18:58
  • \$\begingroup\$ @Draco18s Adding the GraphicRaycaster did the trick, will you add it as an answer so I can accept it. \$\endgroup\$ – Demonic218 Jan 8 at 19:21
2
\$\begingroup\$

You need a graphic raycaster

The nearest direct parent Canvas of any UI element which is top receive mouse input needs to have a GraphicRaycaster component.

This is not to say that the button's patent needs this, but the first patent in the hierarchy that already had a Canvas needs to have it. In your case, likely the UIOverlay object in your scene hierarchy list, though it is possible that it is the GameOver object.

Unity automatically attaches both when you create any UI element with the GameObject menu, however if you are building UI yourself, or make use of child canvases (this can be a good thing) you need to attach a GraphicRaycaster if any element of that canvas needs mouse input.

\$\endgroup\$
  • 1
    \$\begingroup\$ I recommend the linked videos. Timecodes are approximate where the speaker talks about UI and canvases. \$\endgroup\$ – Draco18s Jan 8 at 19:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.