Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Grid Layout spacing not uniform between all cells

Discussion in 'Editor & General Support' started by CDAfonsoCl, Mar 3, 2024.

  1. CDAfonsoCl

    CDAfonsoCl

    Joined:
    May 18, 2021
    Posts:
    17
    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.

    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.

    upload_2024-3-3_12-47-9.png

    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?
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    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.
     
    CDAfonsoCl likes this.
  3. CDAfonsoCl

    CDAfonsoCl

    Joined:
    May 18, 2021
    Posts:
    17
    Pixel perfect solved my problems, but the performance went from 60+fps to 15fps. Any tip?
     
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,551
    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.
     
    CDAfonsoCl likes this.
  5. CDAfonsoCl

    CDAfonsoCl

    Joined:
    May 18, 2021
    Posts:
    17
    Thanks @halley. 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.