How to change size and position of scroll rect cells?

As title says, I’m trying to change the size and position of the cells inside the scroll rect., I have it set up with content or container having a grid layout attached, constraint set to fixed column count. The first cell is an image with text child. I’m creating a copy of this in script and adding it to the scrollrect but when I try changing the size with

newitem.GetComponent<RectTransform>().sizeDelta = new Vector2 (300,300);

it still appears with the size set in the scrolling area.

Likewise with position, it sticks to scrollrect setting.
I have a content size fitter on the child of the item.

The GridLayoutGroup contains the controls for how big a cell is. Look for .cellSize I think it is.

Also, try to avoid crazy psycho-ninja code like this:

Make a public field, drag the thing you want in:

public GridLayoutGrid myGrid;

Then manipulate it directly:

myGrid.cellSize = new Vector2 (100,50);
2 Likes

If you aren‘t that far into making GUI: use UI Toolkit.

Thanks. I’m having a look now. … and lol all of my code is psycho ninja. Probably a lot of stuff that would make a grown man cry :slight_smile:

I’m not sure what ui toolkit is, but I think it’s too late for me now.

Yep GridLayoutGroup changes the cellsize but for all of the cells. I’m trying to change the cells independently as I add them for different sized items but still have them in the grid and scrollable.

I tried adding a layout element (during gameview testing) to the cells that I’m adding but still position won’t change.

Got it now! And it still scrolls with all the changed sizes and placements. Thanks for pointing me in the right direction.