Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mouse Clicks not detected in new Input System

Discussion in 'Input System' started by schilbiz, Aug 23, 2021.

  1. schilbiz

    schilbiz

    Joined:
    Dec 16, 2016
    Posts:
    5
    Hello,

    I am currently on Unity version 2021.1.15f1.

    I created an Action of Type Button that uses a Binding of Left Button [Mouse], while running the game when I click the left mouse button it does not call the associated function. As a test I added a Gamepad button and it called the function as expected. (don't think its script related)
    upload_2021-8-23_0-2-25.png

    I have an Input System UI Input Model (Script) assigned to a game object.
    I have an Event System added as well.
    upload_2021-8-23_0-5-34.png

    In the Input Debugger I see that it registers the mouse clicks.
    upload_2021-8-23_0-4-48.png

    Keyboard and Gamepad input works fine.

    I am making sure I click on a UI element that should detect the raycast, but should that even be necessary?

    Any ideas what the issue might be? It's a Logitech G300S mouse.
     
  2. schilbiz

    schilbiz

    Joined:
    Dec 16, 2016
    Posts:
    5
    I tried a different mouse today with the same results, Input Debugger detects the clicks, but the Game does not.
    ¯\_(ツ)_/¯
     
  3. schilbiz

    schilbiz

    Joined:
    Dec 16, 2016
    Posts:
    5
    After further testing I notice that when I right click in the Game view it changes from Move tool to View tool. This is starting to seem like a bug?

    upload_2021-8-23_20-47-28.png
     
  4. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Your event system makes use of the left click so you either need to check it another way like "Mouse.current.leftButton.wasPressedThisFrame" or maybe you can edit the eventsystem parameters.
     
    wrzwicky and schilbiz like this.
  5. schilbiz

    schilbiz

    Joined:
    Dec 16, 2016
    Posts:
    5
    Well that worked, I felt like I was missing something obvious. Thanks

    Found this after the fact, thought it might be useful for someone looking for similar info:
    https://docs.unity3d.com/Packages/com.unity.inputsystem@0.9/manual/Migration.html

    I ended up using something similar to below, not wanting to run code in Update() if not required:

    Code (CSharp):
    1. private InputAction leftMouseClick;
    2.  
    3. private void Awake() {
    4.     leftMouseClick = new InputAction(binding: "<Mouse>/leftButton");
    5.     leftMouseClick.performed += ctx => LeftMouseClicked();
    6.     leftMouseClick.Enable();
    7. }
    8.  
    9. private void LeftMouseClicked() {
    10.     print("LeftMouseClicked");
    11. }
     
    Last edited: Aug 25, 2021
  6. Daniel-Garcia-S-V

    Daniel-Garcia-S-V

    Joined:
    Nov 11, 2014
    Posts:
    1
    Hi there, what I did in my case is to open the "Input Action" asset and in your control schemes, select the keyboard scheme you created and edit it to add a Mouse control. Like this:
    upload_2022-1-1_21-55-43.png
     
    Kaldrin, anson134, FuriousEX and 14 others like this.
  7. Raincolt

    Raincolt

    Joined:
    Jan 15, 2019
    Posts:
    13
    Just playing around with the new input system and couldn't get mouse to work, you nailed it. Thanks.
     
    Seshua likes this.
  8. Alexvbfpn

    Alexvbfpn

    Joined:
    Jul 10, 2017
    Posts:
    1
    I LOVE YOU THANKS, YOU SAVED ME
     
  9. GaelTFernandez

    GaelTFernandez

    Joined:
    Feb 10, 2017
    Posts:
    7
    For me, the issue was that I had a child object with a canvas group and the option "Block Raycasts" enabled. Once I disabled it, mouse click was back!

    upload_2023-4-19_10-43-23.png
     
    spaghettiSyntax likes this.
  10. euivtui4h

    euivtui4h

    Joined:
    Aug 28, 2017
    Posts:
    4
    FOUND IT!
    If for you too well the InputManager is not accepting the inputs from the mouse and or not detecting its being used used (ie Control Schemes to know when a KBN or gamepad is used).
    Then ensure that in your "Kb and mouse" scheme the Mouse is first in the list.
    Unity Version : 2021.3.5f1
    fffunity.png
     
  11. ringleaderwilliam

    ringleaderwilliam

    Joined:
    Jan 11, 2023
    Posts:
    2
    Hinuko likes this.
  12. RamonLion

    RamonLion

    Joined:
    Jul 19, 2012
    Posts:
    11
    An other option I found which was my solution is to:

    Window > Analysis > Input Debugger > Options > Add Devices Not Listed in "Supported Devices"


    For some reason my basic mouse was not considered supported.
    2021.3.14f1
     
    Censureret likes this.
  13. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    45
    Life saver thank you