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
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 ! (either by scrolling on my app), changing the value in the editor or doing the above code.
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…