Is there any way to easily disable button clicks in a ScrollRect that's currently scrolling?

Basically when the ScrollRect is scrolling and I press my pointer or finger on the screen to make it stop, if where I press my finger happens to be on top of a button, that button’s click event will also be triggered.

I basically want the ScrollRect to just stop on the first click, and for none of the buttons to be triggered (unless the ScrollRect is not scrolling). I was hoping there was a more robust and efficient manner of doing this besides checking if the ScrollRect’s velocity is equal to 0. Any tips?

Place an invisible click-blocker over the content in the scroll view, write a script that monitors the scroll velocity of the the ScrollRect and toggle the click-blocker to when the velocity is crosses some threshold value. This script can also be a button and set the ScrollRect’s velocity to zero when it detects a click.

1 Like

I did pretty much exactly what sindrijo described, it worked great! If you use the unity built-in scroll view and click on the content, it automatically removes the scroll rect’s velocity, so you don’t need to do that manually!

Enjoy :slight_smile:

    public ScrollRect scrollRect;

    public GameObject scrollClickBlocker;

    bool blockerActive;

    void Update()
    {
        if (blockerActive == false && Mathf.Abs(scrollRect.velocity.y) > 40f)
        {
            blockerActive = true;
            scrollClickBlocker.SetActive(true);
        }
        else if (
            blockerActive == true && Mathf.Abs(scrollRect.velocity.y) <= 40f
        )
        {
            blockerActive = false;
            scrollClickBlocker.SetActive(false);
        }
    }