# Dividing sprites and checking for empty ones

So I have a sprite. I would like to divide this sprite into 5x5 sprites. Now what I am confused with is how I can go through each of these sprites and check if a sprite is completely empty/no pixels then remove that sprite

This is my code for dividing the sprite

public class TextureDivider : MonoBehaviour {

public Texture2D source;

// Use this for initialization
void Start () {

GameObject spritesRoot = GameObject.Find("SpritesRoot");

for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
Sprite newSprite = Sprite.Create(source, new Rect(i*128, j*128, 128, 128), new Vector2(0.5f, 0.5f));
GameObject n = new GameObject();
SpriteRenderer sr = n.AddComponent<SpriteRenderer>();
sr.sprite = newSprite;
n.transform.position = new Vector3(i*2, j*2 , 0);
n.transform.parent = spritesRoot.transform;
}
}
}
}

• Presumably you looked at the GetPixels32 method, to get a block of pixel data you can search through to find non-transparent pixels? Jul 29, 2019 at 11:35
• Personally I'd advice against checking every pixel of an image to see if its empty, unless of course you are just messing around for fun. What are you trying to accomplice? maybe there's a better way. Jul 29, 2019 at 14:17