How do you tell if a scrollbar is visible in a scrollview

I would like to alter some variables if the scrollbar is not visible, and change them back if they are.

Notice, this is the scrollbar that is present in GUI.BeginScrollView, not GUI.VerticalScrollbar

I suppose you’re using GUILayout methods inside the ScrollView. If so, you could a) calculate the width of the whole GUI area which includes the eventual scrollbar, then b) get the size of the first wide element you draw (using GUILayoutUtility.GetLastRect): if it’s less then the whole area then the scrollabar is present, otherwise not.

The trick I use is based on EditorGUILayout (might work with GUILayout too). What it does is to use GetLastRect before and after calling EndScrollView and EndHorizontal or EndVertical and compare two values to see if the ScrollView is smaller.
It’s a bit of a hack but it works for me. Make sure the calls to GetLastRect happen only when there’s a Rapaint event like below.

After drawing some stuff, for example, in the OnGUI function, here we get the y value from the rect resulting from GetLastRect.

// SCROLL BARS VISIBILITY DETECTION PHASE 1
float scrollBar__y = 0f;
// To catch whether scrollbars are visible we get the y value now and the height value later
if (Event.current.type == EventType.Repaint)
{
      scrollBar__y = GUILayoutUtility.GetLastRect().y;
}

Then we close our views. In my case I had a horizontal too.

EditorGUILayout.EndScrollView();
EditorGUILayout.EndHorizontal();

…and we call GetLastRect again to look up the height value. I am not sure why we have to look up 2 different variables but… whatever…

// SCROLL BARS VISIBILITY DETECTION PHASE 2
float scrollBar__height = 0f;
// We now get the height and then
if (Event.current.type == EventType.Repaint)
{
    scrollBar__height = GUILayoutUtility.GetLastRect().height;
}

Finally compare the 2 values y and height and find out whether those ScrollBars are visible.

// SCROLL BARS VISIBILITY DETECTION PHASE 3
// Determine whether scrollbars are visible
if (Event.current.type == EventType.Repaint)
{
    if (scrollBar__y > scrollBar__height)
        scrollBarsVisible = true;
    else
        scrollBarsVisible = false;
}