Hi. I’m keeping a expandable list of elements within my ScrollRect and I’m trying to automaticly scroll to the bottom of the rect each time a new element is added.

First I thought it should be done this way:

scrollRect.verticalScrollbar.value = 0;

But it did nothing, literally the scrollbar didn’t change its value. So… the ScrollRect class sets the value of the scrollbar by itself. In this case I tried to set it with the ScrollRect instance:

scrollRect.verticalNormalizedPosition = 0;

But each time this line is executed, I get the error:

UnassignedReferenceException: The variable m_ViewRect of ScrollRect has not been assigned.
You probably need to assign the m_ViewRect variable of the ScrollRect script in the inspector.

I’m assured I have set up the “content” and “vertical scrollbar” properties of ScrollRect in inspector. Any ideas what am I doing wrong?

Just to be sure, some logs:

scrollRect.verticalScrollbar.value = 0.5f;
Debug.Log( scrollRect.verticalScrollbar.value ); => 0.5
Debug.Log( scrollRect.verticalNormalizedPosition ); => 0
// even after those lines value of the scrollbar in the inspector is still set to 1

Canvas.ForceUpdateCanvases();
scrollRect.verticalScrollbar.value=0f;
Canvas.ForceUpdateCanvases();

well the first Canvas.ForceUpdateCanvases() is a must… the second one just depend on what you do

Works for me in Unity 5.1:

GameObject.Find ("Scroll Rect").GetComponent<ScrollRect>().verticalNormalizedPosition = 0.5f;

A much simpler solution is to do a

    yourScrollRect.velocity=new Vector2(0f,1000f);

But I agree it would be more intuitive to change the scrollbar value, that was what I tried first too.

Try it. It is work for me.

Canvas.ForceUpdateCanvases ();

messageScrollRect.verticalNormalizedPosition =0f;

Canvas.ForceUpdateCanvases ();

Using Unity 5.6 my verticalNormalizedPosition can’t be set to 0. That is, it is set to zero but looks like to update right after.

Thus, the verticalNormalizedPosition can’t be set to round zero and for long messages some lines won’t be visible.

To solve this “overwriting”, it’s necessary to wait for the canvas to update with a “yield return null”.

Canvas.ForceUpdateCanvases();

// Wait.
yield return null;

scrollElem.verticalScrollbar.value = 0f;
Canvas.ForceUpdateCanvases();

Is there no fix for this on 2017? I have a content fitter that should be resetting the content size of the scroll viewer when items are added or removed, yet it does not change the content rect height, until I force the scrollbar value to change ! :frowning: (either by scrolling on my app), changing the value in the editor or doing the above code.

The above works but seems like a hack.

@fwalkerCirca

Just set the on value changed for the object scrollview and set its ScrollRect.verticalNomalizedPosition to 0 and it will auto scroll when content is added automatically? like this…
alt text