Scroll rect height with dynamic content

Hi,
I have a scroll rect with some buttons on a grid layout group, the number of buttons is dynamic via c# script. How can I determine the bottom of the rect transform of the content?

If you attach a Content Size Fitter to the scroll rect (assuming that has the grid layout group attached) then you can set the Vertical Fit to “Preferred Size” which will automatically update to the size needed to cover all your elements as they are added/removed.

The thing to note about Content Size Fitters is that they require a layout component attached to the RectTransform they are attached to in order to get the “preferred size” otherwise it returns zero and you won’t see anything at all.

Hope that helps a bit.

Thanks I did not know how to use a content size fitter, I’ll try that