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

Question/Issue With Pixel-Perfect Images (Half Pixel "Snapping")

Discussion in 'UGUI & TextMesh Pro' started by Valynx, Aug 21, 2014.

  1. Valynx

    Valynx

    Joined:
    Mar 22, 2013
    Posts:
    5
    So I have a Canvas, set to Screen Space - Camera and Pixel Perfect. I have a Reference Resolution script on that Canvas set to 640x360. (Slightly odd that the RectTransform then displays 640x359.8939 as the width and height, but I'm sure that's no big deal.) The game is a low-res pixel art game.

    The pixel-perfect pixel "snapping" (for lack of a better word) seems to function kind of strangely, at least in the realm of individual pixels for pixel-art. When moving sprites they can essentially snap to two different widths. I've also noticed that overlaid sprites of different sizes seem to "snap" in different spaces (i.e. not to the same "pixel"). I've attached a couple of screenshots illustrating the issues.

    A - The First "Width"
    a.png
    B - The Second "Width"
    b.png

    Notice the width in relation to the bright purple pixel on the right. Exactly the same scale, just shifted slightly to the right. I'd guess one side is getting rounded up to the next pixel and the other size isn't. Ideally the whole image should shift along one pixel.

    C
    c.png

    These are two separate Images on the same canvas, no scaling or anything. The green line is a single pixel of the image. It should line up exactly with the bottom edge and left edge of the other image but doesn't line up with either.

    It's entirely possible I'm doing something wrong in either of both of these cases. If not it would be awesome if we could get better support for low-res/pixel-art UIs. This is unfortunately kind of a big issue for our game. I'm loving everything else I've messed with so far!
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Hi,

    It's hard to tell much from these images. I can't see which things are separate elements, what is anchored to what, if any elements have half-pixel sizes or stretching, etc. If you make a bug report with a repro project and clear repro steps, then we can look further into it and determine if it's a bug or not.

    Thanks
     
  3. Valynx

    Valynx

    Joined:
    Mar 22, 2013
    Posts:
    5
    Haha, sorry! I thought I'd tried to be clear by adding the images.

    The purple background, green sprite and black sprite are all separate images. All anchoring is default, the only thing that isn't default is the positioning.

    I'll go ahead and send a bug report and project over as well.

    Thanks for your help!
     
    runevision likes this.
  4. leo-carneiro

    leo-carneiro

    Unity Technologies

    Joined:
    Sep 1, 2011
    Posts:
    49
    Hi,

    I just investigated your bug with Runes help. And we have bad news and good news.

    Let's start with the bad one: What you describe is by design.
    When pixel snapping elements that don't have a integer sizes, you have two options, either you guaranteed that their sizes will be constant, but the spacing between elements can vary, or you guarantee that their sizes can vary but the spacing between elements will remain constant.
    We have chosen to make the spacing constant, this guarantees for instance that if you put two elements besides each other without a gap, if you move or resize them, there will be no gap between them.

    Now let's go to the good news: There is a simple workaround you can use to make sure your elements do not resize while moving.
    Instead of moving the element directly, create an empty GameObject and make it the elements parent, and use the parent to move it instead. This should fix your issues.

    Hope this helps :)