- Home /
Is Some UI Element Focused or not ?
Hello,
I made a simple Unity UI, but I encounter a problem.
The UI is supposed to work with Controller AND Mouse.
If I use only the mouse, or if I use only the controller, it work correctly, but if for exemple, I use the mouse and then the controller, I cannot select anything with the controller.
The reason is, if I click outside of the buttons, nothing has focus, and so the controller can't navigate from nothing =>
check this :
If I click back or hover a button, it work correctly again.
My Question is, Is there a way to do something like
if(UI.ElementWithFocus == null){
defaultElement.Select();
}
So that, when nothing is hovered or selected, I can set the focus on the last element selected? So that even if I navigate with controller and Mouse, nothing breaks ?
Thanks
$$anonymous$$aybe EventSystem.currentSelectedGameObject is the one that would work for this? Or if that fails, maybe iterating over Selectable.allSelectables could help?
And then you could either use Selectable.Select()
or EventSystem.SetSelectedGameObject().
Your answer
Follow this Question
Related Questions
Unity5 UI - How to trigger button click event while preventing menu item deselect event? 1 Answer
How to get component of any button that is clicked? (Using same function for every button) 2 Answers
Make a button selectable for controller but not interactable 0 Answers
Unity UI Button states 1 Answer