Forum rules - please read before posting.

Help navigating Unity UI menus with keyboard/gamepad

v1.86.0
Unity 2022.3.57f1

I'm trying to set up navigating menus with the keyboard/gamepad but I'm running into problems with the cursor overriding selections.

Images are all my settings. I'm using the Pause menu to test. I have "directly navigate when paused" checked.

Event System: https://drive.google.com/file/d/1u_RJDzEQFKSeGZKY8qHzajGSEjYkO5u4/view?usp=sharing
Menu Manager: https://drive.google.com/file/d/19O6TR6XDHtJPsTBxcKZwUpVVdCbQ58Lz/view?usp=sharing
Settings Manager: https://drive.google.com/file/d/1MTJRfgIWAkGf8I36xNSsLB8MHCO4Wifo/view?usp=sharing

Scenario 1: Using mouse and keyboard. I press escape to bring up the pause menu. For a split second I can see the first element highlighted before it un-highlights. I assume this is because the mouse is off to the side and the mouse overrides navigation.

Scenario 2: I switch to using my gamepad. I can see in the instantiated event system that the input switched to my gamepad. When I press start it brings up the pause menu but the middle element (Save) is permanently selected. I assume this is because the cursor gets locked to the center of the screen and it automatically highlights save. I can't navigate the menu with my gamepad because of this.

Scenario 3: I disable "use simulated cursor for UI events." I can now navigate the menu with keyboard/gamepad but I can't select anything with the mouse.

Question: I want to be able to select elements while in mouse + keyboard mode but when I switch to a controller I need to be able to navigate without the mouse.
Bonus question: Is there a way to either prevent menu elements from being deselected when the cursor isn't highlighting them (basically an element should be highlighted at all times) or a way to disable only the mouse at run-time?

I can write my own actions and edit scripts I just want to sort out what AC handles natively and what I need to customize.

Comments

  • The behaviour it sounds like you're expecting ought to be the behaviour you get.

    If a Menu is set to be directly-navigable, then the mouse shouldn't factor in, the first element should remain auto-selected, and then navigable with the keyboard or gamepad (depending on Input Method).

    The "Simulated Cursor" should only factor in if you use keyboard or controller input to navigate the Menu that is not directly-navigable. In this case, the cursor is used but moved through these inputs and not with the mouse.

    The only issue I can recreate is that the mouse will affect the highlighting of whichever element it appears over, such that both that and the first element appear selected, but it doesn't affect the ability to navigate directly. I'll look into this, but your Scenario 1 and 2 specifically shouldn't be occurring.

    As you're dealing with two control schemes, try temporarily unchecking the Auto Sync Control Scheme option so that your Input method remains as Mouse And Keyboard. Putting the Gamepad aside for the moment, does Scenario 1 still occur?

    I wonder if your wider issues are related to your Unity version, which also affects which version of the Input System package is available.

    In a backup/test project, see if these issues occur in a later release, Unity 6.3 or 6.4.

  • edited July 16

    Updated to 6.3 and AC 1.86.4 still experiencing the same behavior.

    I disable Auto Sync Control Scheme. Scenario 1 still occurs.

    I'm going to create a fresh project to help troubleshoot.

  • edited July 16

    Started fresh project. Loaded the 3D game demo. I enable all the directly control toggles which are disabled by default in the demo. I can navigate all menus with the keyboard but checking these options disables mouse navigation of the menu elements. Left click selects the highlighted element.

    I noticed in the manual screenshot for navigating menus directly (page 415) there's a toggle under global menu settings for "Disable mouse when directly-controlling Unity UI Menus?." It's not present in the current version of AC. Is this option enabled or disabled by default?

  • Try using the New Game Wizard rather than the 3D Demo, as you can use it to install a fresh Input System Integration template, as well as set the "Default interface" to Unity UI on the last page.

    With this initial setup, I don't get the behaviour of the mouse-clicks affecting a direct-controlled menu.

    Is this option enabled or disabled by default?

    Good spot, thanks for pointing that out. Yes, that's an old option that's since been incorporated into the Optional Mouse Input Module, but that's exclusively for Unity's legacy Input Manager system and isn't available for use with Input System.

  • edited July 18

    Created a new game in the wizard.

    So gameplay menus behave as I would expect them to. I can cycle interactions with keyboard and mouse separately.

    But pause menus completely ignore mouse inputs when Directly navigate when paused option is set. In the default unity ui pause menu uncheck "pauses game" and add a select element action in the turn on slot. I can navigate with mouse and keyboard.

    Check "pauses game" the mouse stops working.

  • edited July 19

    pause menus completely ignore mouse inputs when Directly navigate when paused option is set

    This is actually the intended behaviour. AC's menu navigation is one or the other - relying either on the cursor, or direct-navigation.

    Forgive me if I understood your earlier description. If you're now finding that the mouse isn't interfering when the keyboard should take precedence, that's correct. A custom script can be used to dynamically alter the intended options (e.g. "Directly navigate when paused?") based on the last-used input device if necessary, but first it's important to have the different configurations (i.e. mouse-control, keyboard control) work as intended in isolation.

    Putting the gamepad aside for the moment, how do you wish for the Pause menu to react to input? Should it switch navigation modes dynamically while the user switches between mouse and keyboard control, without turning off?

  • I want to navigate paused menus using **both** mouse and keyboard simultaneously.

    I can do this for menus that run during gameplay with an action to select the first element (this is a documented feature). I want this feature to also work with menus that pause gameplay.
  • edited July 19

    Basically I want to recreate the functionality seen here

    https://drive.google.com/file/d/10CKMpnG4EzfhWZjO9w7BR1Vht0karxXv/view?usp=sharing

    I want to

    A: navigate a paused menu with the mouse
    B: navigate the same menu with the keyboard
    C: keyboard should precedence over navigating menus e.g. if the mouse is highlighting a UI element and I press a direction, the next element should be selected (I depict this in the final 5 seconds of the video).

    All three are possible with gameplay menus but are impossible with paused menus.

  • The "Select element" Action trick to allow for simultaneous direct-navigation should work when the Menu is paused, too - but make sure the "Directly navigate when paused?" option is unchecked so as not to disable mouse input.

    Try running this Action alone in the Pause menu's "ActionList when turn on" asset, removing the default Actions as part of the test.

    AC itself leaves the navigation / selection to the Event System, outside of optionally selecting the element through the Action / Menu's properties. One quirk of the Event System's behaviour is that "clicking off" the Menu causes the direct-navigation to be lost as well.

    A custom script would be needed to manually re-select the intended element - AC provides a helper function for this with:

    AC.KickStarter.playerMenus.SelectUIElement(gameObject);
    
  • Thank you very much Chris. When I tried to select an element on a paused menu I remember it deselecting but I'll chalk it up to user error. With your helper I wrote a script that does what I want.

    using UnityEngine;
    using UnityEngine.EventSystems;
    using AC;

    public class ReselectUIElement : MonoBehaviour
    {
    private GameObject lastSelected;

    void Update()
    {
        EventSystem es = EventSystem.current;
        if (es == null) return;
    
        GameObject current = es.currentSelectedGameObject;
    
        // Remember the last selected element
        if (current != null)
        {
            lastSelected = current;
            return;
        }
    
        // If nothing is selected + the mouse was clicked reselect last element
        if (Mouse.current != null &&
            (Mouse.current.leftButton.wasPressedThisFrame ||
             Mouse.current.rightButton.wasPressedThisFrame))
        {
            if (lastSelected != null)
            {
                KickStarter.playerMenus.SelectUIElement(lastSelected);
            }
        }
    }
    

    }

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.