Why is this not batching?

Hi!,

I have a custom editor, that adds objects to the scene when clicked in some parts.

Objects are created in a procedural fashion (they are just quads), here the code:

GameObject go=new GameObject("Perraca");

MeshRenderer r=go.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
r.material=mat;
				
Mesh m= new Mesh();

Vector3[] verts={new Vector3(0,0,10), new Vector3(0,10,10),new Vector3(10,10,10), new Vector3(10,0,10)};
m.vertices=verts;
				
int[] indices={0,1,2,2,3,0};
m.triangles=indices;

Vector2[] uv={new Vector3(0,0), new Vector3(0,1),new Vector3(1,1), new Vector3(1,0)};
m.uv=uv;

MeshFilter filter=go.AddComponent(typeof(MeshFilter)) as MeshFilter;
filter.mesh=m;

m is a material that you drag onto the available window slot. In my case it was just a Diffuse material. I was expenting this to batch, but each quad gets its won render call (stats say so). Could anybody see why?

Edited: Some more info. If I create 2 GameObjects from the GameObject menu (Plane Objects) and set its material to same than I used when creating the objects, it batch :S. Pretty odd. Could it be because the way mesh is creatd?.

Thanks in advance,
HexDump.

This should help:

r.sharedMaterial = mat;  //instead of r.material = mat;

Only objects with the same material are batched

Hi!,

Thanks for the answer, I have been out for some months and need to remember this things again :smile:.

Eskema: Ummm, me suenas de gp32spain? :smile:

HexDump.

Me has pillado XDD

For anyone else reading this post who would like to know why this was an issue, please read the following resources: