Creating gameobjects using script and assigning sprites to some of them breakes batching (both static and dynamic). Bug?

So I create some gameobjects using a script :

public Sprite spr;

	void Start ()
    {
        for (int i = 0; i < 100; i++)
        {
            GameObject obj = new GameObject();
            SpriteRenderer rend = obj.AddComponent<SpriteRenderer>();
            rend.sprite = spr;
            obj.transform.position = new Vector2(i,i);
        }
	}

This does what you expect it to do (it batches). However if I only assing sprites to some of them :

public Sprite spr;

	void Start ()
    {
        for (int i = 0; i < 100; i++)
        {
            GameObject obj = new GameObject();
            SpriteRenderer rend = obj.AddComponent<SpriteRenderer>();

            if (Random.Range(0,2) == 1)
            {
                rend.sprite = spr;
            }

            obj.transform.position = new Vector2(i,i);
        }
	}

The batches and setpass calls increase alot (depending on the amount of gameobjects that dosen’t get a sprite assing). I’ve even tried making the objects static :

public Sprite spr;

	void Start ()
    {
        for (int i = 0; i < 100; i++)
        {
            GameObject obj = new GameObject();
            SpriteRenderer rend = obj.AddComponent<SpriteRenderer>();

obj.isStatic = true;

            if (Random.Range(0,2) == 1)
            {
                rend.sprite = spr;
            }

            obj.transform.position = new Vector2(i,i);
        }
	}

And it turnes out that it even breaks static batching, all this leads me to belive that this is a bug. Does anybody have an explanation to why this is happening or should I report this as a bug?

Here’s a picture to clearify : (Look at setPass calls and Batches)

I wouldn’t jump the gun and blame Unity for bugs just yet, chances are, you’re missing something. I presume that when you add a Renderer, it’s also creating a new material. Try assigning a shared material to all of the Renderers.

//pseudo
public Material mySharedMaterial;
..
renderer.sharedMaterial = mySharedMaterial;

Also if you want instantiated objects to be statically batched, then you need to combine them with the Static Batching Utility