Scrollview and ScrollTo function

Hello, I am creating a Level select that is scrollable vertically only, and the level sets are placed from bottom to top (first level set is on bottom scrollview and last available level set is on start of scrollview).

My goal is to automatically scroll the scrollview to the last unlocked level => I found that this can be done via ScrollTo function. My problem is that the ScrollTo function will find scroll value which is placing desired visualelement to bottom of screen. The problem arises, because I have menu back button placed over level select on bottom part of screen. So I need to add some offset to found scroll position, to remove overlapping between desired visualelement and back button . On attached image you can see described problem, my goal is to have scrollto visualelement above red line.

I’ve already tried:

  • create empty visualelement of desired height as child of button, but I am worried, that these objects will have some performance impacts, because from my unity experiences with old ui many objects in scrollview caused spikes (it is possible, that in one scrollview will have maybe 200 level buttons…)
  • use the scrollOffset property, but I couldn’t get the required behavior

Is it possible to create this via some easy and elegant solution? Thank you! :slightly_smiling_face:

Hello! scrollOffset should be the way to go. What problems are you having?

scrollOffset holds the scroll position, so you should be able to set it to the button position + an offset to avoid the back button overlap. In fact, I think you could even use ScrollTo to move to the scroll view to the right position and then add the offset by adding to the existing scroll offset:

scrollOffset = new Vector2(scrollOffset.x, scrollOffset.y + 50);

Hello, thank you very much for your help. I tried simmilar approach, but it doesn´t worked, you helped me with genius idea: “I think you could even use ScrollTo to move to the scroll view to the right position and then add the offset by adding to the existing scroll offset”. Thank you! :slight_smile: