Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    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:
    134
    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.
     
    schilbiz likes 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
     
  7. Raincolt

    Raincolt

    Joined:
    Jan 15, 2019
    Posts:
    12
    Just playing around with the new input system and couldn't get mouse to work, you nailed it. Thanks.
     
unityunity