I have a scrollview set up inside my canvas. I would like to set the position of that scroll view to a specific gameobject in the content section of the scroll view. How would I do this?
Or even just programmatically change the position of the scroll position inside of the scroll view. Thanks
Now the script is ok, but the content behaves oddly. Sometimes it works, as the desired element is visible (but the content seems “randomly” positioned vertically) ; and sometimes not, as the element remains off screen.
I must specify that my UI content is a complex spreadsheet with lines and columns, so it uses a lot of Layout components (Groups, Elements) and moreover a Content Size Fitter on the Content game object. I suspect this to be the problem, as the size of the Content may be recalculated with some delay.
Also my Canvas has a Canvas Scaler which may cause additional mess.
I will try your script with a more simple content… but I still need a solution to my own problem.
Be aware that this will act on both content’s x and y position.
If you want to modify only one coordinate, let’s say the vertical one, use this code instead :