Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. 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


    Mar 22, 2013
    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"
    B - The Second "Width"

    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.


    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


    Nov 28, 2007

    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.

  3. Valynx


    Mar 22, 2013
    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


    Unity Technologies

    Sep 1, 2011

    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 :)