Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple case in the new InputSystem

Discussion in 'Editor & General Support' started by Erdal42, Apr 21, 2020.

  1. Erdal42

    Erdal42

    Joined:
    Sep 17, 2018
    Posts:
    19
    Hi guys!

    First, I'd like to say that the new input system is a blast!! :))

    There is a simple case that I can't do though: I want the same Action to give me the current pressed position in the screen, either with touchscreen or mouse. The problem is that there is no Property (binding path) giving the pressed mouse position for a specific mouse button.

    This won't work as it will give me pressed position only for touchscreens and will give me position everytime for mouse (even when not pressed). And asking for inputAction.isPressed in the callback throws error when used outside of a Button type Action :


    And there is no interaction where you can choose a mouse button.

    Did I miss something?

    Thanks all :)
     
    Last edited: Apr 21, 2020
  2. Erdal42

    Erdal42

    Joined:
    Sep 17, 2018
    Posts:
    19
    After some digging it appears that paths should be present on input actions screen, but there aren't.

    So I made a little workaround that keeps the game device agnostic (works only with the generated C# script, not with the PlayerInput component) :

    Code (CSharp):
    1.         private void OnMoveTo(CallbackContext context)
    2.         {
    3.             // Workaround as current input system doesn't support full mouse paths
    4.             if (context.control.device == Mouse.current && !Mouse.current.leftButton.isPressed)
    5.             {
    6.                 return;
    7.             }
    8.  
    9.             moveToPosition = context.ReadValue<Vector2>();
    10.         }