Search Unity

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

Is it possible to rebind mouse scrollwheel on new input system?

Discussion in 'Input System' started by kypronite, Apr 28, 2021.

  1. kypronite

    kypronite

    Joined:
    Apr 15, 2013
    Posts:
    21
    I'm referring to the code RebindActionUI.cs in new unity input sample project.
    The rebind is working fine for mouse buttons and keyboard but it neglect scroll wheel.
    I'm using action.PerformInteractiveRebinding(binding Index) method.

    Currently I'm using scroll wheel so player can change weapon at realtime,
    kind of awkward if player can rebind mouse button but not scroll wheel
    in controls mapping menu.

    In my input mapping,
    scroll wheel is configure 1 D axis mapping
    with Scroll y/[Mouse] for both positive and negative composite part.
     
    CleverAI likes this.
  2. I do this, but I'm using ActionType: Value and ControlType: Axis. The 1D Axis is a composite. I don't think the scroll wheel is a compatible control with it (at least I didn't find a way).
     
    CleverAI and kypronite like this.
  3. kypronite

    kypronite

    Joined:
    Apr 15, 2013
    Posts:
    21
    I did research after I posted this thread...but then I notice WithExpectedControlType()
    randomly while browsing unity input documentation
    and then try it out of blind luck and suddenly it is working, it manage to capture and rebind scroll wheel.
    In unity input sample project, the WithExpectedControlType("axis") is not included.

    jumpAction.action.PerformInteractiveRebinding()
    .WithExpectedControlType("axis") //add this to bind to scroll wheel
    .OnMatchWaitForAnother(1f)
    .OnComplete(operation => RebindComplete())
    .Start();

    I putting this up just in case others end up here through google search.
     
    CleverAI, jukibom and Lurking-Ninja like this.
  4. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    53
    That's an interesting discovery! The only problem with that is it maps it like ... well, an axis. You can't assign something to just mouse scroll up etc.
     
  5. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    I have a similar problem and couldn't solve it anymore with InputSystem 1.3.0 and Unity 2020.3.31.f1. The input itself works this way as seen in the screenshots, but I couldn't bind the scroll wheel to an 1D axis anymore, as I did with the gamepad. Unfortunately, this means I can not rebind at runtime any other button to the zoom in/out.




    Is there a way to overcome this problem? I would want to setup the scroll/y positive and scroll/y negative value separately in the Input Action Map.
     
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    In the upcoming 1.4, we've added individual scroll directions. I.e. you can now bind to scroll up, down, left, or right individually. Obsoletes having to mess around with processors on X or Y bindings.

    ////EDIT: This stuff comes in the form of a new
    DeltaControl
    type which is also used for deltas. So, bindings can now also be made directly to moving the mouse up/down/left/right, for example.
     
  7. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    That sounds exactly what I need. Thank you.

    When can I expect the new version 1.4?
     
  8. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    My hope is it will finally make its way onto the production server end of next week or so.
     
  9. safronov_da

    safronov_da

    Joined:
    Aug 4, 2021
    Posts:
    1
    The problem is also relevant for me, I am also looking forward to the new version
     
  10. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    It seems you guys couldn't made it. Let's see if after easter holidays we get a new version.

    Moreover, I have an additional problem for you:
    It's about the onAnyButtonPress Event and the documentation example. If I use the IDisposable as mentioned and exit play mode in Unity Editor, I get two errors, which are neglectable, but still.

    This is the documentation example.
    Code (CSharp):
    1. // Script that will spawn a new player when a button on a device is pressed.
    2. public class JoinPlayerOnPress : MonoBehaviour
    3. {
    4.     // We instantiate this GameObject to create a new player object.
    5.     // Expected to have a PlayerInput component in its hierarchy.
    6.     public GameObject playerPrefab;
    7.  
    8.     // We want to remove the event listener we install through InputSystem.onAnyButtonPress
    9.     // after we're done so remember it here.
    10.     private IDisposable m_EventListener;
    11.  
    12.     // When enabled, we install our button press listener.
    13.     void OnEnable()
    14.     {
    15.         // Start listening.
    16.         m_EventListener =
    17.             InputSystem.onAnyButtonPress
    18.                 .Call(OnButtonPressed)
    19.     }
    20.  
    21.     // When disabled, we remove our button press listener.
    22.     void OnDisable()
    23.     {
    24.         m_EventListener.Dispose();
    25.     }
    26.  
    27.     void OnButtonPressed(InputControl button)
    28.     {
    29.         var device = button.device;
    30.  
    31.         // Ignore presses on devices that are already used by a player.
    32.         if (PlayerInput.FindFirstPairedToDevice(device) != null)
    33.             return;
    34.  
    35.         // Create a new player.
    36.         var player = PlayerInput.Instantiate(playerPrefab, pairWithDevice: device);
    37.  
    38.         // If the player did not end up with a valid input setup,
    39.         // unjoin the player.
    40.         if (player.hasMissingRequiredDevices)
    41.             Destroy(player);
    42.  
    43.         // If we only want to join a single player, could uninstall our listener here
    44.         // or use CallOnce() instead of Call() when we set it up.
    45.     }
    46. }
    and these are the errors when exiting play mode:
    -----------------------------------------------------------------
    ArgumentException: Event must be a StateEvent or DeltaStateEvent but is a TEXT instead
    Parameter name: eventPtr
    UnityEngine.InputSystem.InputControlExtensions.EnumerateControls (UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, UnityEngine.InputSystem.InputControlExtensions+Enumerate flags, UnityEngine.InputSystem.InputDevice device, System.Single magnitudeThreshold) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Controls/InputControlExtensions.cs:1024)
    UnityEngine.InputSystem.InputControlExtensions.GetFirstButtonPressOrNull (UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, System.Single magnitude, System.Boolean buttonControlsOnly) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Controls/InputControlExtensions.cs:1105)
    UnityEngine.InputSystem.InputSystem+<>c.<get_onAnyButtonPress>b__79_0 (UnityEngine.InputSystem.LowLevel.InputEventPtr e) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/InputSystem.cs:2404)
    UnityEngine.InputSystem.LowLevel.SelectObservable`2+Select[TSource,TResult].OnNext (TSource evt) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Utilities/Observables/SelectObservable.cs:43)
    UnityEngine.InputSystem.LowLevel.InputEventListener+ObserverState.<.ctor>b__2_0 (UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, UnityEngine.InputSystem.InputDevice device) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Events/InputEventListener.cs:127)
    UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue1,TValue2] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`2[TValue1,TValue2]]& callbacks, TValue1 argument1, TValue2 argument2, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Utilities/DelegateHelpers.cs:71)
    UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
    UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
    -----------------------------------------------------------------
    ArgumentException while executing 'InputSystem.onEvent' callbacks
    UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
    UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
     
  11. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    I am testing right now Input System 1.4, which you put on github. I downloaded the source code and replaced the 1.3 version in my project "Library\PackageCache\com.unity.inputsystem@1.3.0" with the new files in "InputSystem-1.4.0\Packages\com.unity.inputsystem".

    It works. I have tested the new "scroll/up" and "delta/up" for the mouse and it works too.

    Nevertheless, the interactive rebind seems not to work for these new settings. It still registered for the scroll input "scroll/y" instead of "scroll/up" and "scroll/down". Moreover, the delta input for the mouse gets not registered at all during the interactive rebind event.

    Same situation for left and right stick of a gamepad. I press left stick up, it registered "leftStick/y" instead of "leftStick/up" and vice versa.

    Any suggestions for that?
     
    Last edited: May 4, 2022
    Amvos likes this.
  12. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    By looking through the Input System code I found out that potential InputControl candidates are ordered by a score. It seems that the input with an axis x/y has a higher score than the one directional candidates up/down/left/right.

    I created a separate function in the OnComplete event, which checks if the new binding is a stick or scroll axis and then ApplyBindingOverride for other InputControl candidate instead. Seems to work fine as the second candidate is always the input I wanted.

    For the delta mouse movement I found out that in "PerformInteractiveRebinding" the "WithControlsExcluding("<Pointer>/delta")" function were used. So now it's obvious why it doesn't check for the mouse delta movement. Unfortunately, as it is written in the source code, I can't change it, otherwise Unity Editor rebuilds the package and reset it to InputSystem 1.3

    Any idea how I can build around it?
     
    Amvos likes this.
  13. HugeWill

    HugeWill

    Joined:
    Nov 4, 2016
    Posts:
    27
    @CleverAI If you want packages not to rebuild when you edit the code just click on the develop button

    upload_2022-6-2_8-27-38.png

    Is there an update for when version 1.4 will be getting released?
     
    CleverAI likes this.
  14. Amvos

    Amvos

    Joined:
    Apr 8, 2020
    Posts:
    3
    Hey I am working with the new input system (1.4.4) and having the same trouble as you had. When I try to rebind to Scroll/up instead of Scroll/y I get Scroll/y. I tryed to look how you did it but couldn't find how you changed the InputControl candidate. How did you do it?
     
  15. Stephen1701

    Stephen1701

    Joined:
    Mar 29, 2016
    Posts:
    132
    I'm having the same trouble.
    Mine is set up so that using GetBindingDisplayString() it gets the name of the binding and applies the name to the button in the UI in game, so the user can see what button does each action
    When I set the action to a 1D Axis in the input asset, the name of the binding gets read in as "scroll up" and "scroll down"
    upload_2023-2-28_18-26-43.png
    upload_2023-2-28_18-27-33.png

    However, if I then play the game and rebind the actions(which uses the function PerformInteractiveRebinding) by scrolling the wheel up and scrolling the wheel down, the binding name comes back as "scroll wheel". Then if I scroll the wheel in game the action is not performed. So when rebinding it is not differentiating scrolling up or scrolling down.
    When putting breakpoints in my code, it seems that if I use the wheel up or down, it is sending callbacks for both actions.
    So scrolling the wheel up and down is now recognised as "scroll wheel" whatever that is referring to, instead of up and down.
    upload_2023-2-28_18-29-19.png

    When printing out the paths, I can see that it recognises up and down, but the control just won't work. Any advice please?
    upload_2023-2-28_18-36-28.png
     
    Last edited: Feb 28, 2023
  16. GameDeveloper234

    GameDeveloper234

    Joined:
    Apr 21, 2023
    Posts:
    7
    Have you found a solution to this problem?
     
  17. GameDeveloper234

    GameDeveloper234

    Joined:
    Apr 21, 2023
    Posts:
    7
    Have you found a solution to this problem?
     
  18. Dennooo

    Dennooo

    Joined:
    May 12, 2015
    Posts:
    88
    Bump - I'm also looking for a solution for this one.
     
  19. pablobr89

    pablobr89

    Joined:
    Sep 2, 2021
    Posts:
    1
    Hi! I found a solution to rebind mouse scroll up or down instead mouse scroll y. I only used .WithControlsExcluding("<Mouse>/scroll/y") this way RebindingOperation can listen scroll up or scroll down.

    Example of my code

    Code (CSharp):
    1.         _rebindingOP = _action
    2.             .PerformInteractiveRebinding(_keyMapping.compositeIndex)
    3.             .WithControlsExcluding(_action.bindings[_keyMapping.compositeIndex].groups)
    4.             .WithControlsExcluding("<Mouse>/scroll/y")
    5.             .WithExpectedControlType("axis")
    6.             .WithCancelingThrough(cancelKey)
    7.             .OnMatchWaitForAnother(0.1f)
    8.             .OnApplyBinding((operation, path) => OnApplyBinding(operation, path))
    9.             .OnCancel(operation => RebindComplete(true))
    10.             .OnComplete(operation => RebindComplete(false))
    11.             .Start();
     
    G_ard and jukibom like this.
  20. G_ard

    G_ard

    Joined:
    Apr 10, 2018
    Posts:
    1
    You're a lifesaver, thank you so much.