- Home /
Lines appear between sprites from sprite sheets
I'm having this strange bug where lines appear between sprites from a sprite sheet:
This can happen when the import settings for the sprites are set to Repeat rather than Clamp.
It can also happen if you're using bilinear filtering in combination with a sprite sheet. The shader will actually sample from adjacent pixels in the sprite sheet when doing the filtering.
Answer by NiceNinja · Jan 12, 2017 at 08:46 AM
I encountered a similar issue and found that the cause was the "Anti Aliasing" setting on the Quality Settings for the project. The default for my project was "2x Multi Sampling" for the "Beautiful" and "Fantastic" build settings. Setting this to "Disabled" removed the lines.
Before
After
Thank you so much, this solution helped me with all my frustration, i thought the line is showing because i imported the sprite in a wrong way, all import setting have been set to my need but i dont know that the quality setting also affect the sprite image in Unity
Answer by CodeAndWeb · Sep 24, 2015 at 02:20 AM
Do you create the sprite sheet inside unity? Or do you import a sprite sheet from outside?
The reason for this OpenGL. There are a bunch of ways to fix the issues - one or more of them should fix your problem:
1) If you build the tile atlas yourself make sure to surround each tile with a 1 pixel border that repeats the tiles outer pixels. Pixels from neighbor tiles might be dragged in otherwise. This is what I would expect is your main issue here. I guess under the tile with the green line is a grass tile inside your atlas.
2) Texture's "Filter Mode": Set it to "Point" - linear or bilinear might drag in pixels from neighbor tiles.
3) Make sure your coordinates and sizes are all full pixels. Don't try to draw a tilemap at a pixel position 0.5 - this will create artifacts at the sprite borders - you'll see the background flashing through. But this is not the case here - the line would be gray not green.
Answer by TruffelsAndOranges · Sep 23, 2015 at 07:40 AM
This is a problem in Unity. I also have this behaviour.
This is a problem in any system that uses sprite sheets with mip maps and/or anything but point sampling. A general solution is to duplicate the sprite edges so when the bilinear sampling goes over the edge it will get the same color. I was thinking Unity's sprite packer has the ability to do this but I don't have Unity in front of me to find it.
Exactly. And that's the problem. There should be an in-built solution to prevent these things, but I don't think there is. Haven't found it atleast.
It would be nice if there were something built in, yes. But this may be something that's difficult to generalize. Do a search for "color dilation" for some solutions you can apply to your sprites beforehand. Unity has Photoshop actions to help as well (although I never had much luck using them).
Answer by Alex_May · Sep 23, 2015 at 05:47 PM
This is floating point precision, it is not Unity-specific, and the solution is usually to add a bleed pixel around the edge of each tile. It isn't something Unity can itself fix as various filtering rules will blend those pixels anyway, so fixing it for nearest neighbour point sampling won't have an effect on, say, bilinear filtering.
Add a bleed pixel and offset your tile positions to account for it.