Hi, I’m creating an Inventory System for my game. I’ve used Scriptable Objects to resemble the Items inside the Inventory and sorted them using a Grid Layout Group. My question is whether you can offset your grid layout group on specific rows, so that the items would line up with the Inventory background (Image with example items and how they dont line up). Solutions/Tips would be much appreciated ![]()
Hey! Interesting problem.
My first thought is to use something a little more flexible than GridLayoutGroup. Unity doesn’t include it by default, but you can add a package called com.unity.uiextensions which includes a component called FlowLayoutGroup.
The basic idea is that it arranges elements of variable sizes into a grid with similar constraints. Use a LayoutElement on each of your elements and set their PreferredWidth and PreferredHeight to your target size.
An approach for offsetting every other row would be to have “spacer” objects that are half the size of those hexagons on each side of every other row. Their PreferredWidth would be half of your hexagon objects. You can also achieve this with a single VerticalLayoutGroup with several HorizontalLayoutGroups beneath it, but adding/removing things will be a bit less intuitive.
With that being said, this solution highly depends on whether you’d like to have your row/column counts change, or if you’re just looking to add/remove hexagons. If it’s the former, I would suggest looking into some pre-existing hexagon inventory code, or write your own system to handle the positions.
Good luck!
