Search Unity

New Input System and Scroll Rect - bug when clicking on scrollbar?

Discussion in 'Input System' started by Evyatron7, Mar 5, 2020.

  1. Evyatron7

    Evyatron7

    Joined:
    Mar 6, 2019
    Posts:
    18
    Hello,

    It seems that when using the new Input System UI Input Module component, clicking on a Scrollbar inside a ScrollRect instantly scrolls all the way to the bottom.
    Some observations:
    1. I'm on 2019.3.2f1 and preview-05.
    2. When I disable the InputSystemUIInputModule and enable StandaloneInputModule the bug no longer presents.
    3. The instant-scroll happens whether I click the Handle or anywhere inside the Scrollbar area.
    4. If I keep the mouse button held down and then drag - it fixes itself and I can scroll the Handle perfectly.
    5. This happens regardless of content inside the ScrollRect.
    6. Dragging inside the content area works well.

    Is this a known issue?


    Thanks!
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Yup, there's an open ticket for this and a fix in flight that will hopefully land and ship with preview.6 this week.
     
  3. Evyatron7

    Evyatron7

    Joined:
    Mar 6, 2019
    Posts:
    18
    Ah I was just searching for "scrollrect" and couldn't find it - I guess it was a a more low-level fix.

    Thanks for the quick reply!
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    After a QA pass, turns out there's still issues with scrollbars even with the recent batch of fixes to UI so there's likely still going to be some problems with preview.6. I promise we'll have a look for the package after that.
     
  5. Evyatron7

    Evyatron7

    Joined:
    Mar 6, 2019
    Posts:
    18
    Oh ok, thanks for the update! Since the primary input method is a controller, and the mouse does work when dragging the content and using the mouse wheel - it's not really that big of an issue.

    Will keep an eye out :)
     
  6. Foulcloud

    Foulcloud

    Joined:
    Mar 23, 2014
    Posts:
    19
    In my case, ScrollView/ScrollRect is not useable because of this issue. Stuff just jumps around too much when clicking on the scroll bar. Looking forward to a fix. Thank you.
     
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    This turned out to be a problem in the uGUI scrollbar code where it retains an event object (which are cached and thus reused) and runs a coroutine on it over several frames. uGUI team is handling it from here. I expect there will be a fix in an upcoming uGUI package.
     
  8. Niclaskjellberg_TO

    Niclaskjellberg_TO

    Joined:
    Apr 1, 2020
    Posts:
    3
    Good to know. Is there a bug tracked for this issue that we can follow?
     
  9. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    There is an open ticket on the issue tracker. A fix is in flight on Unity trunk. I'll check about backports.
     
  10. vecima

    vecima

    Joined:
    Jun 6, 2017
    Posts:
    16
    Not to thread hijack, but using the new Input System (and the old one too for that matter) scroll rects have never worked with gamepads or keyboard for me without extra code. Am I just mapping the controls wrong? Or missing something else? Are these supposed to work with gamepads out of the box?

    EDIT: I should have pointed out that even using the below code has some problems:
    - I can't easily get a gamepad or keyboard to select Selectables listed in the scroll rect unless i select one with the mouse first.
    - I'm using the right stick to scroll, and I'm not sure why but the right stick input (at least on Dualshock 4 & Xbox One) is also selecting the next item in that direction, probably via the "Navigation" settings on the selectables.
    - Ideally selecting a selectable on a scroll rect would cause it to scroll to a position such that the entire selectable is visible. it doesn't scroll at all based on contents being selected.

    In order to get scroll rects to scroll around with a controller I've been adding this class:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.EventSystems;
    6.  
    7. [RequireComponent(typeof(ScrollRect))]
    8. public class ScrollableArea : MonoBehaviour, IMoveHandler
    9. {
    10.     private ScrollRect scrollRect;
    11.     private const float speedMultiplier = 0.4f;
    12.     private float xSpeed = 0;
    13.     private float ySpeed = 0;
    14.     private float hPos;
    15.     private float vPos;
    16.  
    17.     void Awake ()
    18.     {
    19.         this.scrollRect = this.GetComponent<ScrollRect>();
    20.     }
    21.  
    22.     public void OnMove(AxisEventData e)
    23.     {
    24.         this.xSpeed += e.moveVector.y * (Mathf.Abs (this.xSpeed) + 0.1f);
    25.         this.ySpeed += e.moveVector.y * (Mathf.Abs (this.ySpeed) + 0.1f);
    26.     }
    27.  
    28.     public void SetScroll(Vector2 scrollAmount)
    29.     {
    30.         if (scrollAmount.x != 0f) {
    31.             this.xSpeed += scrollAmount.x * (Mathf.Abs (this.xSpeed) + 0.1f);
    32.             //this.xSpeed *= scrollAmount.x;
    33.             this.hPos = this.scrollRect.horizontalNormalizedPosition + this.xSpeed * speedMultiplier;
    34.             this.xSpeed = 0;// Mathf.Lerp (this.xSpeed, 0, 0.1f);
    35.             if (this.scrollRect.movementType == ScrollRect.MovementType.Clamped)
    36.                 this.hPos = Mathf.Clamp01 (this.hPos);
    37.         } else {
    38.             this.hPos = this.scrollRect.normalizedPosition.x;
    39.         }
    40.         if (scrollAmount.y != 0f) {
    41.             this.ySpeed += scrollAmount.y * (Mathf.Abs (this.ySpeed) + 0.1f);
    42.             //this.ySpeed *= scrollAmount.y;
    43.             this.vPos = this.scrollRect.verticalNormalizedPosition + this.ySpeed * speedMultiplier;
    44.             this.ySpeed = 0;// Mathf.Lerp (this.ySpeed, 0, 0.1f);
    45.             if (this.scrollRect.movementType == ScrollRect.MovementType.Clamped)
    46.                 this.vPos = Mathf.Clamp01 (this.vPos);
    47.         } else {
    48.             this.vPos = this.scrollRect.normalizedPosition.y;
    49.         }
    50.         this.scrollRect.normalizedPosition = new Vector2 (this.hPos, this.vPos);
    51.     }
    52. }
    And then I have separate code that looks for "Scroll" input (Mapped to "Right Stick [Gamepad]") and calls SetScroll with the ReadValue<Vector2> result.
     
    Last edited: Apr 8, 2020
  11. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    174
    Hi...
    Was the fixed ever deployed? reading the ticket they seem to mention fixed in UGUI 1.0.0, I have that version with 2019.3.13 and still have the same issue.
     
    cxode likes this.
  12. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    Same here, Unity 2019.3.8f1.
     
  13. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    Would be great to get a dev response on this (@Rene-Damm ?). I'm on the latest version of the package and still experiencing the issue. If this isn't fixed before our game comes out I'll have to make my own scrollbar to replace the built-in scrollbars, and that would be silly.
     
  14. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    You'll need to update to the latest patch release. The fix versions are the following: 2019.3.14f1, 2020.1.0b8, and 2020.2.0a8.
     
    cxode likes this.
  15. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    Thank you very much! That fixed it. I left a comment on the issue tracker page to let others know they need to update the Unity editor. In the future it would be much appreciated if you note when an editor update is required. That wasn't clear at all from the issue tracker page, which only stated a package version in which the issue was fixed.
     
  16. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Good point. I'll try to get this into the process.
     
    cxode likes this.
  17. BeVRStudios

    BeVRStudios

    Joined:
    Feb 27, 2021
    Posts:
    1
    Hi. I found the same behavior on 2019.3.14.f1, but with XR Interaction Toolkit, but upgrading Unity version did not help. Is there any other way to fix this?
     
  18. Redtail87

    Redtail87

    Joined:
    Jul 17, 2013
    Posts:
    125
    I'm seeing that same issue, even in the unity example project with 2019.4.11f1.
    Upgrading unity to 2020 seems to fix the issue. The fix might be in a later version of 2019 but didn't try them.