I’m trying to create a pause menu in which the buttons can be controlled via KEYBOARD.
The problem is I either cannot make the buttons to be highlighted as default when the pause screen opens yet they get highlighted after the first key press OR I can highlight the first button as default BUT this time the system insists on selecting that only 1 button and cannot navigate through other button objects. If I press the down arrow I can see it quickly flashes as if it tries to change the selection to the next button but fails.
This is probably because that the SetSelectedGameObject is called continuously in Update and it is strictly assigned to the button “selectedBut”. That’s why it insists on highlighting that button. But if I don’t do that, this time no button gets highlighted as default when pause screen is opened until I press an arrow key.
I think I have to add some kind of a “listener” in order to change the currently highlighted button but couldn’t figure how or from where I should do that.
Here is my code…
I’ve also tried playing around with “es.currentSelectedGameObject” with no luck.
After I played around with different scenes, I have seen that there is no problem with the main Title screen.
First button is highlighted as default and everything works well with navigating keyboard.
The problem occurs in the “in game/pause” menu. Since there are also player controls available and probably whole EventSystem is focused on that one, when I jump into PAUSE menu, the first item isn’t highlighted by default as opposed to main title menu and I need to press down arrow and navigate to the second item in order to let the “highlighting” start working and ACTUALLY activate the focus on pause menu.
In the main scene where the title menu is, there is ONLY ONE CANVAS.
However, in the scene where pause menu is present, there is another canvas, making that level actually has two canvases. One for pause menu itself and one for the scene.
Probably there becomes a FOCUS conflict either between the ingame controls and the pause menu UI OR there is a conflict between the two canvases on the second scene.
Here is what it looks like,
WORKS PROPERLY. WHEN STARTED, 1st ITEM in MENU IS HIGHLIGHTED
IntroScene
|
I’ve also tried disabling the other canvas and the problem still persists. So, it is not about two canvases fighting over focus. It’s about the input controls not being transferred from character control to the pause menu. I have to push a button for the menu to get the necessary focus.
Need help… Have tried many things without luck. Don’t know if this is kind of a bug since most people design their games for mouse and control pad interfaces nowadays and this can be something skipped about complete keyboard control.
I’m pretty sure it would have a solution regarding the event listeners but I have no idea how to solve this.
Same thing here.
I’ve tried: UnityEngine.EventSystems.EventSystem.current.firstSelectedGameObject = reference.GetComponent<UnityEngine.UI.Button>().gameObject;
But no luck.
Thing is, I remember in another game I made previously, the event system automatically focused on activated elements by default, as with the main menu. Also, sometimes it does not focus at all, so even worse than having to press the keys first.
I just had a thought, maybe if you keep menus in different canvases and activate each canvas, and not the menus Inside the canvas?