Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

New Input System Not Highlighting UI Button On Second Pause

Discussion in 'Input System' started by deckercj28, Jan 17, 2020.

  1. deckercj28

    deckercj28

    Joined:
    Sep 27, 2018
    Posts:
    4
    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!
     
    bsdtooloosee and MortenLyk like this.
  2. Drakonhawk

    Drakonhawk

    Joined:
    Feb 7, 2020
    Posts:
    6
    Thanks a lot. With this workarround I could fix the button highlighting in pause menu.
     
  3. Schneddi

    Schneddi

    Joined:
    Nov 12, 2017
    Posts:
    8
    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.
     
  4. MortenLyk

    MortenLyk

    Joined:
    Nov 13, 2013
    Posts:
    2
    I have noticed same issue in 2020.1.3f1 with Input System 1.0.0
     
  5. Wilshirebs

    Wilshirebs

    Joined:
    Jun 27, 2019
    Posts:
    1
    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.
     
  6. WesselG

    WesselG

    Joined:
    May 26, 2020
    Posts:
    2
    It is adressed here.
     
    frankkubrick3, Solphist and tbaxter like this.
  7. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    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.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3.  
    4. public class FirstMenuButton : MonoBehaviour
    5. {
    6.     public void SetFirstButton(GameObject button)
    7.     {
    8.         EventSystem.current.SetSelectedGameObject(null);
    9.         EventSystem.current.SetSelectedGameObject(button);
    10.     }
    11. }