Search Unity

Resolved Mouse Events Not Firing (New Input System)

Discussion in 'Input System' started by RichmarIII, Aug 6, 2021.

  1. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    No mouse events are firing at all, and all
    Code (CSharp):
    1. Action.ReadValue()
    calls return null. All other events for other devices such as keyboard and game-pads fire normally. When i look at the Input debugger

    <Mouse>/Delta/x
    and

    <Mouse>/Delta/y
    Are missing. Here is a picture of my ActionMap:
    ActionMap.PNG

    And here is the missing

    <Mouse>/Delta/x
    When game is running:
    Missing.PNG

    When using a gamepad, the device is actually visible in the input debugger like so:
    Controller Not Missing.PNG

    using
    Code (CSharp):
    1. Mouse.Delta.x.ReadValue()
    Does actually work in code, but is not a valid solution to my problem in a local co-op scenario.
     
    Last edited: Aug 6, 2021
  2. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    INPUT PROBLEM FIXED! so, the issue was that ONLY mouse events were not being registered as noted in the thread. well, if i use the
    PlayerInput
    Component (which I have been) on a
    GameObject
    that was added in the editor during design-time, mouse events actually work, but, if you spawn a GameObject at runtime that has the
    PlayerInput
    Component, THAT is when mouse events don't work (which is what I was doing). So, this simple line of code fixed it:

    Code (CSharp):
    1. GetComponent<PlayerInput>().enabled = false;
    2. GetComponent<PlayerInput>().enabled = true;
    disable and re-enable. Also, simply doing:

    Code (CSharp):
    1. GetComponent<PlayerInput>().enabled = true;
    Does not work. you have to disable first, then re-enable the
    PlayerInput
    Component and mouse events will work!

    [UPDATE]
    So, disabling and re-enable did work, but I found out it caused an unintended side effect: other players could not join. All input devices would be registered to the existing player instead of a new input device spawning a new player. So, the real fix, after trial and error and detective work (literally hours debugging code) was to created a Control Scheme in the InputAction Asset. What was happening was the
    PlayerInputManager
    was joining players when an
    InputAction
    was triggered, in this case, the "Jump" Action and what the
    PlayerInputManager
    was doing behind the scenes was tying the InputDevice that triggered the event to the new player. So, in this case, since the space bar was pressed, ONLY the keyboard was assigned to the player, NOT the mouse. When the Gamepad was pressed, then a new player was created and only the Gamepad was assigned to it. When I initially "solved it" by disabling then re-enabling the
    PlayerInput
    , the side affect was that when it got re-enabled, it assigned it access to ALL input devices behind the scenes instead of tying it to only the keyboard. So, I could use the mouse, but no other player could join because the
    PlayerInputManager
    thought the new device belonged to player 1. The REAL solution was to create a Control Scheme in the InputAction Asset
    and mark the desired devices as required for that particular Control Scheme so that when the
    PlayerInputManager
    detects input from a device, it actually assigns all the devices marked as required for that particular Control Scheme
     
    Last edited: Aug 7, 2021
    Connorses likes this.
  3. TtroubleTT2

    TtroubleTT2

    Joined:
    May 2, 2023
    Posts:
    2
    Blessed Be to You I spent 2 hours tryna figure this out