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. Dismiss Notice

Bug Virtual Mouse not monitored

Discussion in 'Input System' started by abegue, Oct 20, 2022.

  1. abegue

    abegue

    Joined:
    Jan 28, 2019
    Posts:
    24
    Hello,

    Here is the context:
    I am working on a video game where I want the player to be able to switch easily between the keyboard/mouse and gamepad. When using the gamepad, I want to enable a virtual mouse input that will allow the player to navigate in UI like it can with the mouse.

    The issue:
    When the player starts using the gamepad, the player input automatically switches on the gamepad control scheme. On a custom script, I detect this control scheme change and enable (
    gameObject.SetActive(true)
    ) the cursor (Virtual Mouse Input, taken from the samples in Input System). However, when I try to click the button with the virtual mouse, nothing happens.
    Until I move the mouse. Then the virtual mouse works as expected.
    It is an issue in that, most of the time, the user will take its gamepad, switching the control scheme, and is not going to interact with keyboard/mouse from here.

    Temp.gif
    Description:
    - gamepad is activated
    - the virtual mouse click works
    - switch on keyboard/mouse control scheme
    - the cursor is disabled
    - switch again on gamepad
    - the cursor is enabled
    - the cursor can be moved *but* the click does not work anymore

    Investigation:
    I dig on to investigate what I've been missing. I found that state changes from my Virtual Mouse (even if added to the InputSystem) are never monitored.
    So, in the
    InputManager.UpdateState
    , the
    ProcessStateChangeMonitors
    call returns false, preventing
    FireStateChangeNotifications
    to be called, forwarding click event and so on.
    So why does it work when moving the mouse? Because it triggers an event (I think it is due to the control scheme change) that will call the
    InputManager.AddStateChangeMonitor
    method, refreshing the monitors and will finally add the Virtual Mouse to the
    m_StateChangeMonitors
    , fixing the issue.


    Perhaps it is me that did not understand how to setup correctly the virtual mouse and/or switching correctly the activation, so I am searching for help about that or what new code line I should add to the Virtual Mouse so my virtual mouse becomes monitored correctly.

    Note: I tried calling
    InputUser.PerformPairingWithDevice(m_VirtualMouse, _playerInput.user)
    to force pairing and monitoring, but it did not work. Also, I try adding the Virtual Mouse among the
    playerInput.currentActionMap.devices
    because it forces the monitoring refresh. But it didn't work (my real mouse was not working anymore).
     
  2. abegue

    abegue

    Joined:
    Jan 28, 2019
    Posts:
    24
    Bump!