for (int i = 0; i < matrices.Length; i++)
{
var mat = Matrix4x4.identity;
mat.SetTRS(transform.position+Random.insideUnitSphere*100f, Quaternion.identity, Vector3.one*200f);
matrices[i] = mat;
}
Graphics.DrawMeshInstanced(meshToRender, 0, material, matrices);
If I run this the meshes are visible, but obviously without the performance benefit:
for (int i = 0; i < matrices.Length; i++)
{
var mat = Matrix4x4.identity;
mat.SetTRS(transform.position+Random.insideUnitSphere*100f, Quaternion.identity, Vector3.one*200f);
matrices[i] = mat;
Graphics.DrawMesh(meshToRender, matrices[i], material, 0);
}
What are the possible reasons that DrawMeshInstanced wouldn’t be working for me? I’m not doing anything with the shader yet, but I thought that was just for if I wanted to pass specific material properties to each instance.
EDIT: sounds like either incorrect version of unity, or perhaps using batching and instancing together? only one can be used not both
EDIT 2: looks like you did not read all of that manual page:
Batching priority
When batching, Unity prioritizes Static batching over instancing. If you mark one of your GameObjects for static batching, and Unity successfully batches it, Unity disables instancing on that GameObject, even if its Renderer uses an instancing Shader. When this happens, the Inspector window displays a warning message suggesting that you disable Static Batching. To do this, open the Player Settings (Edit > Project Settings > Player), open Other Settings, and under the Rendering section, untick the Static Batching checkbox.
Unity prioritizes instancing over dynamic batching. If Unity can instance a Mesh, it disables dynamic batching for that Mesh.
I was using version 5.5.4 and I had read instancing was supported since 5.4 but updating to 2017 does make the checkbox appear, so that could have been it.
Now that I got it to work with the standard shader, now my goal is to make my own shader that works with instancing.