New Input System Not Highlighting UI Button On Second Pause

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!

2 Likes

Thanks a lot. With this workarround I could fix the button highlighting in pause menu.

I ran into the same problem. Since the solutions lead to unfavorable code, I switched back to the old UI system. Still use the new Input System for the player Input in game.

I have noticed same issue in 2020.1.3f1 with Input System 1.0.0

I am having the same issues with the new input system with UI, I can see in the event system the correct button is selected, but it shows the normal colour, until I hit up and down which then it switches to the proper selected colours.
It would be nice to see the API be updated with code to show how to make the new input system work instead of moderately useless lines with no explanation.
Very annoying because the old system worked reliably, and I don’t think I can go back to the old UI as I want my game to accept many controllers, and the new Input system is pretty great for that.

It is adressed here.

3 Likes

What an annoying need to do a work around.

The video above inspired the following script, so that I could call SetFirstButton(GameObject) using the OnClick() events.

using UnityEngine;
using UnityEngine.EventSystems;

public class FirstMenuButton : MonoBehaviour
{
    public void SetFirstButton(GameObject button)
    {
        EventSystem.current.SetSelectedGameObject(null);
        EventSystem.current.SetSelectedGameObject(button);
    }
}