Gaps sometimes appearing between 2D sprites

When the camera is moving, both in game and in the Unity editor, 1 pixel wide gaps between my sprites will appear (see enlarged example below). I’ve read this is potentially due to z-fighting, and I have tried altering the clipping settings on the camera but the problem still persists.

Can anyone shed some light on why this may be occurring?

Extra info that may be of use:

  • The sprites pictured have been imported using a single sprite sheet which has a texture type of “Sprite” and a sprite mode of “Multiple” and the filter mode is set to “Point”.
  • The background that can be seen bleeding through occasionally (the 1 pixel gap) is also imported as a sprite but with a sprite mode of “Single”. I have tried with the filter mode set to both “Point” and “Bilinear” but both produce the same problem.
  • When positioning the tiles, I held down the “V” key to make them snap together, I have zoomed in as far as possible and can’t see any gap between the tiles when doing this.

I found an answer to this issue that solved it for me, turn off Anti Aliasing in Edit → Project Settings → Quality.

It might not be the solution for everyone, but it worked for the issue I had.

We had this same problem in our project (as I posted before) and eventually fixed it by adding a bleed zone of one extra pixel on each side of each sprite on our sheets. Unity will, as mentioned by others, sometimes display one extra pixel beyond the defined zone on the spritesheet. If that pixel is transparent, it will create gaps (or, depending on the spritesheet, cause other undesirable bleed-over from sprites not meant to be adjacent).

This could be happening because your sprite sheet has a transparent background. When the camera moves or zooms in/out some pixels outside of your sprite’s region can show up due to inaccuracies.

Change your sprite’s texture type to advanced, then you can change the format to RGB 24 bit. Now your sprite sheet no longer has a transparent background.

finally fixed a similar issue on my own project. It was down to the camera orthographic size!

here are the steps I followed to solve this:

  • make sure you are using point filtering
  • use power of 2 textures
  • adapt the screen resolution and the camera orthographic size to prevent floating point imprecision (see rocket5 tutorial and related post) which helped me find the right formula.

I was using a tiling method to build levels with sprite rendered prefabs. When I created the generic sprite-diffuse material so the light would work, I had turned on the “pixel snap” option (I’m not sure why… seemed like a good idea at the time?) This was causing gaps between all the tiles even when nothing was moving in any way, in fact, it did this even without the lighting effect.

When I had this problem, I had to change the “Filter Mode” of my textures to “Point” instead of the default “Bilinear”. I don’t really understand it, I know it has something to do with quality though, and I imagine “Point” is similar to “Pixel Perfect” – which is what you need in this case.

If this is your problem and you care enough to research it, I’m sure there is info on that setting in the docs.

I got it fixed by disabling Anti Aliasing and changing spritesheet max size.

Hi guys I solve my problems just changing quality settings , just set antialising to disable , that’s solved my problem.

turning off pixel snap helped. Also turned off anti-alias from quality settings

In my case the problem was caused by the Pixel Perfect Camara Script(one of Unity’s non-built-in packages), so just turnning it off solved it

A bit of a special case which might not have been mentioned by others: If you are creating Texture2D objects during runtime, they default to using mipmaps with their short object constructor. For me, this resulted in gaps between tiles for my custom tilemap shader at specific camera positions (the Texture2D in question was my tilemap atlas). Took a long time for me to figure out, but it was just a matter of marking false for the mipChain bool in one of the longer Texture2D constructors. More info here: c# - How to change Texture2D type to Sprite during runtime (Unity) - Game Development Stack Exchange

Anyone still suffering from this issue can try this free utility from the asset store.

In the sprite, change the filter mode to “Point (no filter)”