Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Input System breaks UI Toolkit buttons

Discussion in 'Input System' started by Phaz0r18, Apr 23, 2024.

  1. Phaz0r18

    Phaz0r18

    Joined:
    Feb 21, 2013
    Posts:
    10
    Hi all,

    I'm trying to add the new Input System to my existing game; in my scene I have a GameObject with multiple UI Documents which share a 'PanelSettings Asset' in which I'm setting the 'Display' to either 'Flex/none' to show hide each window and some buttons to navigate between.

    After adding the Input System from the Package Manager and enabling the 'Active Input Handling' in the Project Settings>Player as the new Input System, my UI now doesn't react to any Hover or Click actions as they used to. My understanding from reading the docs (https://docs.unity3d.com/Manual/UIE-Runtime-Event-System.html) is that I should only need to add a 'UI > Event System' and add an 'Input System UI Input Module' in order to receive events as previously but this isn't working.

    I have also made sure to add a '.Focus()' call to the container of the first window whenever it is shown. I am also still using the 'DefaultInputActions' on the Input System UI Input Module before trying to get my own player controls working, the Event System has no Game Object for its 'First Selected' field.

    Do I need to add a Player Input component to my UI Documents and map each button click event? How would this work for hover events?

    Edit: Forgot to mention this is with Unity 2023.2.17f1

    Edit1: I can interact with my buttons using the Input Debugger if I manually select 'Enable Device' on the Mouse, is there any reason I would have to do this manually?
     
    Last edited: Apr 23, 2024
  2. beevik_

    beevik_

    Joined:
    Sep 27, 2020
    Posts:
    107
    You menioned you have multiple UI documents. Do they have non-visible elements that overlap? If so, it's possible that a document with a higher sorting order value is stealing your mouse hovers from underlying documents, especially if that document contains transparent "pickable" visual elements that overlap with underlying visual elements from other UI documents. Check your visual element "pickable" settings and make sure the transparent ones using screen space are marked as "ignore".

    Also, which version of the InputSystem package are you using? If you're using 1.8 or above, you should probably be using the project-wide input actions setting. Then, as long as you have an action map called "UI" with the standard "Point" and "Click" actions, your UI Toolkit elements will receive mouse hover events even without setting up EventSystem or InputSystemUIInputModule components.

    Another thing to try is opening the Input Debugger window while your application is running. Then check to see which input actions are active at any given time. You should see the "UI/Click" and "UI/Point" actions if they are enabled.
     
    Phaz0r18 likes this.
  3. Phaz0r18

    Phaz0r18

    Joined:
    Feb 21, 2013
    Posts:
    10
    Hi Beevik! Thanks for taking the time to respond! So I eventually discovered on another forum post that by having the 'Simulator' window open, all Mouse events are redirected to that instead, even though I had it behind my Scene/ Game views, would've been handy for Unity to provide a message but glad that it was an easy fix.

    In regards to your comment about the project-wide input actions and the 'UI' map, I'm having another issue you may be able to help with? If I'm interpreting the docs correctly the "Input System UI Input Module" should provide some out-of-the-box functionality in regards to input with Mouse & Keyboard events.

    Although I'm now able to receive Mouse events I'm having issues pickup up any sort of "Navigation" events, I've duplicated the entire 'UI' Action Map from the default action map to my own and even when manually switching to this action map I'm unable to navigate between any of my on-screen UI buttons using the keyboard.

    I noticed the default action map uses a 'Navigate' action with callbacks to navigate events:

    Code (CSharp):
    1. rootVisualElement.RegisterCallback<NavigationCancelEvent>(OnNavCancelEvent);
    2. rootVisualElement.RegisterCallback<NavigationMoveEvent>(OnNavMoveEvent);
    3. rootVisualElement.RegisterCallback<NavigationSubmitEvent>(OnNavSubmitEvent);
    Are we expected to implement these callbacks to handle UI navigation? If so, how would one access the available focusable elements and choose which to navigate to on move?

    I'm currently using v1.8.1 of the Input System with the UI Toolkit, thanks again!