I am trying to programattically scroll to the bottom of a ScrollView after I add new item. (I am trying to create a log of messages e.g. events that have occurred)
In UI Builder, I have added a ScrollView. In my script I instantiate and add my new item to the ScrollView. After that i try to change the verticalScroller value as per some old tutorials. This will only ever scroll to the top no matter what value i set it to. I have tried 0.0f, 1.0f and some inbetween values.
The highValue is positive if there are more items than can be viewed and negative if there is empty space in the view. This code has the items fill from the top of the view (value = 0) and then forces the last items to be visible (value = highValue). If you want your items to fill from the bottom, always use highValue.
This at least happens in 2022.1.1f1. The Scroller class has a lowValue member but I have never seen it be anything but 0.
The problem was that after removing the last item the list would not scroll to the bottom because the geometry was not updated. I tried using a geometry change event as well as a remove from panel event but that didn’t work. WaitForFixedUpdate() or WaitForEndOfFrame() don’t always work.
Thank you, this was my problem too. After adding text it wasn’t scrolling all the way to the bottom even with the code above. It seems it’s because scroller.highValue wasn’t updating, adding a coroutine fixed it.