GridLayoutGroup Padding

Currently cell size and spacing are using floats. But Padding is a RectOffset which contains 4 integers.
Since my world space canvas uses small values (2d camera height is 2 units), a padding of 1 would offset my cells by 384 pixels on a non-retina ipad.

Are there any plans on changing this RectOffset to use floats or is there another workaround?

1 Like

There were no plans on this but it would probably be a good idea. Noted for consideration!

The padding being int is such a hoser, in which situation does this work out?
Iā€™m building a world space UI for VR and padding in terms of 1 world space unit is a littleā€¦ much.

3 Likes

I was facing the same issue as described in this post, but after a bit of research figured out that the issue (at least in my case) stems from a poor canvas setupā€¦

It turns out that the trick is to ensure that the canvas width/height is somewhat defined as something resembling pixel values, and then the physical size of the canvas in world space should be defined by changing the scale (typically to something very small).

This setup makes it so that any children of the canvas behaves much nicer in terms of anchoring/stretching, and the padding on layout groups also becomes usable since the int value will be in relation to the width/height of the parent, but scaled down through the canvas.

The first few minutes of this video describes the setup nicely:

2 Likes

Iā€™m working on a pixel art game, with a world space canvas for a few things. I canā€™t just make it arbitrarily larger. Everything was going really well until I hit this bump.

Using integer values for padding is such a nonsense.
My world-space canvas was using a neat 1x1 size to simplify calculations. And now I have to resize it to something like 2000x2000 because someone at Unity decided that int for coordinates is fine (and fun probably).

2 Likes

Iā€™m facing the same problem actually.

My cells size are set to .1, and Iā€™m unable to arrange them in that grid if the padding is 1

Especially since for the same components, the ā€˜spacingā€™ field allows for floats. Does Unity not go the same processes of Game development and encounters the same pains and issues as us??

Oh, itā€™s just ridiculous. Ints for paddings?

Does anyone solve this issue (I use it for VR)?

Seems not, because they fired the internal team behind the Gigaya project, so no eating of their own dog food.

I solved the problem by copying the code for LayoutGroup and writing my own CustomLayoutGroup to override the integer padding with floats. Hereā€™s my code for anyone interested

9160547ā€“1274594ā€“CustomGridLayoutGroup.cs (11.3 KB)
9160547ā€“1274597ā€“CustomHorizontalLayoutGroup.cs (1.18 KB)
9160547ā€“1274600ā€“CustomHorizontalOrVerticalLayoutGroup.cs (13.1 KB)
9160547ā€“1274603ā€“CustomLayoutGroup.cs (14.3 KB)
9160547ā€“1274606ā€“CustomVerticalLayoutGroup.cs (1.16 KB)

6 Likes

lmao thatā€™s actually hilarious - arbitrary decade-old limitation in the engine? Just copy the code & fix it yourself!

Truly makes me wonder why this hasnā€™t been implemented. Such a basic feature.