I have a set of UI buttons in a canvas. The user is be able to navigate the buttons through both mouse clicks and arrow key movements. However, clicking anywhere not on the buttons results in focus being lost from the buttons, making arrow key navigation no longer work. Is there a way to solve this?
Focus is handled by the EventSystem component. While you can’t really do much with that, you can easily replace the existing EventSystem component with your own implementation based on their code. You can find it right here:
So the first step is to take that file and put it in your project, changing the file name and class name to something like
MyEventSystem. Also change the
AddComponentEntry attribute argument to something like “Event/My Event System”
Then update the
SetSelectedGameObject method to return early if the
selected argument is
Finally, find the EventSystem GameObject in the scene and replace the EventSystem component on it with your own implementation.
Turns out making your own EventSystem won’t work. Instead, you’ll have to create a InputModule implementation. Here’s one:
Look into changing