Black border around 2D sprite

There seems to be some kind of graphical/rendering bug. I am making different themes for my video game and for some reason, when I switch themes(a different sprite sheet), there’s a black border around it. I made sure the rendering options are the same on both sprite sheets, and both sprites were the same resolution. Can someone please explain why this is happening?

The original themed buttons
86679-blue.png

The new themed buttons
86680-green.png

Hi

I had a few of these occur as well. The actual black line is because the background of your cam is black and Unity is not so happy with your sprite size.

A few things you should check:

  1. Your sprite should be NPOT. If it isn’t make it so and fill the added space with transparency.
  2. Check the filtering and use Point Filtering
  3. Play with the pixel-to-unit size (set it 1-on-1 just to see what happens and adjust from there)
  4. Switch on pixel snapping (i.e. go pixel perfect) or use a custom material with the default sprite shader

Hope these may help you out.

Kind regards,

Koen Matthijs

Setting the created texture to use point filtering seems to give better results:

public static Sprite LoadPNGToSprite(string filepath)
	{
		Texture2D texture = LoadPNG(filepath);

		texture.alphaIsTransparency = true;
		texture.wrapMode = TextureWrapMode.Repeat;
		texture.filterMode = FilterMode.Point;

		float pixelsPerUnit = 100;

		return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), pixelsPerUnit);
	}

I was actually thinking about spending some time learning this Unity graphics engine. So I thought that I would start out with something simple, like putting a border around a sprite then manually creating a map from each sprite with that border. Well that would have been a lot of work for a graphics engine that is supposed to represent 2018, but then I realized what would seem completely illogical. There isn’t a way to put a border around the sprite, wow. I’ll wait for the next future, the real one.