I have a pause menu canvas with a series of buttons that display (Resume, Menu, Restart Level, & Quit) that I have mapped to my escape key on my keyboard, or start button on a gamepad controller. Right now, I have all of the Highlighted, Pressed, and Selected button colors set to gray (Hexadecimal B4B4B4), and I noticed that when I first pause the game, my first selected button in my event system (Resume) highlights perfectly fine, and navigation (including changing to the highlighted button color on other buttons) and click events work great. However, when I pause the game again, this first selected button is displayed with its normal color without the gray highlighted color. What’s even more confusing is that when I navigate down once, the highlighted color goes back to gray, and I can navigate back up to my first selected button and it highlights perfectly fine.
I have an OnPause function that is triggered via my input controls, and the code for that is as follows (also, it may be irrelevant, but I’m processing events in dynamic update from my Input System Package too) :
[SerializeField] private GameObject playerInput;
[SerializeField] private GameObject pauseMenuUI;
public void OnPause(InputAction.CallbackContext context)
{
//disables my player controls, which doesn’t impact my actual UI navigation/control
playerInput.SetActive(false);
//I have this disabled in my editor, so it will display all my buttons once this function is invoked.
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
}
And for the click event for clicking the first selected button (Resume):
public void Resume()
{
playerInput.SetActive(true);
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
}
I showed this to one of my buddies, and he found a good fix for this OnPause, but as he mentioned, it does seem a bit hacky:
//event system handling the new input system
[SerializeField] private EventSystem eventSystem;
//this is mapped to my resume button (my first selected button in my event system)
[SerializeField] private GameObject firstSelectedObject;
public void OnPause(InputAction.CallbackContext context)
{
playerInput.SetActive(false);
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
//added below
eventSystem.SetSelectedGameObject(null);
eventSystem.SetSelectedGameObject(firstSelectedObject);
}
This now shows the highlighted first selected button every time I pause the game, but I had to disable all the mouse events as hover would highlight over another button besides resume and yet my resume button would still be highlighted.
So, I just wanted to see if this is something other people are seeing as well. Let me know if you need any other clarification on anything I mentioned above!