Grid Layout spacing not uniform between all cells

Hello, i have this problem with the Grid Layout i am using to generate a grid on my scene:
Light green color is the background object (image) behind the grid, and it is acting as “line separator” to all the cells, but i am getting different spacing between the cells.

9677408--1379486--upload_2024-3-3_12-44-24.png

I want the lines to be really thin, so i set 1.1f as gridLayoutMain.spacing.

If we zoom in, some lines are getting 1px and other 2px.

Already tried pixel perfect on Canvas, but all the scene gets too blury.
I am using Screen Space - Camera and this app needs to be available on multiple resolutions.

Unity 2022.3.5f

What can i do?

9677408--1379480--upload_2024-3-3_12-38-26.png
9677408--1379483--upload_2024-3-3_12-44-19.png

Are these color blocks images in a spritesheet?
Pixel perfect should be on but you should also check if these images are positioned at exact integer coordinates. Perhaps autolayout interferes with that.

1 Like

Pixel perfect solved my problems, but the performance went from 60+fps to 15fps. Any tip?

I’m confused why you’d think a non-integer 1.1f would result in 1px spacing every time? Ten times 1.1 is 11, so you should expect an extra pixel after around ten boxes, but with rounding, it’s going to be more like after the first 5 boxes, and after the fifteenth, and so on. If the boxes are also not integers, it can happen even more often.

1 Like

Thanks @halley1 . Yes it’s weird, but i will explain:
On the beginning of this project, everything looked fine in Windows builds using 1 (int) value for grid spacing, but when exporting to iOS, in some smaller devices, some lines were not visible. Using 1.1f fixed the issue, but late i realized that on windows i get bigger lines sometimes.
Maybe i will try set different values for different platforms and see if it works.