Search Unity

Sprites sometimes showing pixels from sprites next to them in the sprite sheet

Discussion in '2D' started by Lordomi, Mar 22, 2017.

  1. Lordomi

    Lordomi

    Joined:
    Mar 22, 2017
    Posts:
    2
    There seems to be a problem in both the editor and the game, where a sprite sometimes shows pixels from a sprite directly next to them in a sprite sheet, even though the shown parts weren't selected in the Sprite Editor, like this:
    upload_2017-3-22_17-25-34.png
    On the top of the block, a part of the buzzsaw that is directly above the block in the sprite sheet is shown, even though that area wasn't selected in the sprite editor.
    upload_2017-3-22_17-28-21.png
    Here are the settings of the file if that helps, the sprites are 32x32 in size. Please help, this is a very annoying issue
    upload_2017-3-22_17-30-21.png
     

    Attached Files:

  2. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Getting sprites to display "pixel perfect" is a common problem in Unity, and it's one that I grappled with for a long time. There's a pretty good blog here that explains why the problem happens and it gives some ideas for how to deal with it:

    https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/

    I did a lot of testing before I found something that works, and some of the steps that I do may not even be necessary, but I do them anyways. At some point (I forgot what-- maybe a Unity update) my sprites stopped displaying properly in the editor, but they still look good in builds. Here's some things you should consider:

    - Set your camera to a "pixel perfect" size. I have a PixelPerfectScript component on my camera that does this:
    GetComponent<Camera>().orthographicSize = Screen.height / 2 / pxPerUn
    where pxPerUn is the pixels per unit that you import your sprite sheets at. I believe they need to be a size that is a power of 2.

    - Make your sprite sheets in sizes that are powers of 2.
    - Divide your sprite sheets into cells of sizes that are powers of 2. You may have to fiddle around to ensure that your sprites are positioned correctly because the cells will often be a little (or maybe a lot) bigger than the sprite itself.
    - Give all sprites a material with "pixel snap" enabled.

    I think that's everything. It works great for me, but it's worth mentioning that my game uses a static camera. If your game scrolls, you may have to do a little more.

    EDIT: I forgot to mention that imported sprites should use point filtering.
     
  3. Lordomi

    Lordomi

    Joined:
    Mar 22, 2017
    Posts:
    2
    Thank you for your help, we'll try these solutions out, though I don't really know how to do most of these
     
  4. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Which ones do you not know how to do? I'm happy to help if I can.