I’m gonna take one more angle at my problem of getting dynamic batching to work.
Recap: This answer lets you understand 900 is the max vertice count that can be batched dynamically.
The actual documentation doesn’t deny nor confirm it.
But can anyone make these meshes actually batch ? The script should work by just slapping it on the camera in an empty scene.
Looks like 300 is actually the hard limit (double click on any of the meshes on the created prefabs to see vertice count). Or do i have to change something in project settings to go over 300 ? You can reduce vertice count by reducing “quadsW” to 12 → they will batch.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class VertexTest : MonoBehaviour
{
void Start ()
{
const int quadsW = 13;
const int quadsH = 6;
List<Vector3> verts = new List<Vector3>();
List<int> tris = new List<int>();
for (int qx = 0; qx < quadsW; qx++)
{
for (int qy = 0; qy < quadsH; qy++)
{
makeSquare(qx, qy, 0, verts, tris);
}
}
Mesh m = new Mesh();
m.Clear ();
m.vertices = verts.ToArray();
m.triangles = tris.ToArray();
m.uv = null;//new Vector2[verts.Count];
m.uv1 = null;//new Vector2[verts.Count];
m.uv2 = null;//new Vector2[verts.Count];
m.colors32 = null;//new Color32[verts.Count];
m.colors = null;//new Color[verts.Count];
m.normals = null;//new Vector3[verts.Count];
m.Optimize ();
m.RecalculateNormals ();
Material mat = new Material(Shader.Find("Mobile/VertexLit"));
const int gameobjectsW = 4;
const int gameobjectsH = 4;
for (int x = 0; x < gameobjectsW; x++)
{
for (int y = 0; y < gameobjectsH; y++)
{
GameObject go = new GameObject(x+", "+y);
go.transform.position = new Vector3((x*quadsW) + x, (y*quadsH) + y);
MeshRenderer mr = go.AddComponent<MeshRenderer>();
MeshFilter mf = go.AddComponent<MeshFilter>();
mf.sharedMesh = m;
mr.castShadows = false;
mr.receiveShadows = false;
mr.sharedMaterial = mat;
}
}
Camera.main.transform.position = new Vector3(gameobjectsW * (quadsW+1), gameobjectsH * (quadsH+1), -50 ) / 2f;
}
void makeSquare(int x, int y, int z, List<Vector3> verts, List<int> tris)
{
int statrCount = verts.Count;
verts.Add (new Vector3(x, y, z));
verts.Add (new Vector3(x, y+1, z));
verts.Add (new Vector3(x+1, y+1, z));
verts.Add (new Vector3(x+1, y, z));
tris.Add(statrCount);
tris.Add(statrCount+1);
tris.Add(statrCount+2);
tris.Add(statrCount);
tris.Add(statrCount+2);
tris.Add(statrCount+3);
}
}