Hi,
I am trying to do a custom foliage rendering system in version 2018.3.0f2 and uses DrawMeshInstanced to draw the meshes. It is working without problems when in play mode, but I would like to draw them in the scene view as well to have a visual feedback when painting.
The problem is that in editor, the call to DrawMeshInstanced seems to be kept in memory and keeps being added to when calling it again, making the editor very slow very fast.
The batches keeps increasing until the computer just crash.
I tried to call the render method in different callback but the result is always the same.
So if anyone has any idea how to make that work, I would be very thankful.
The render code:
Mesh mesh = trees[treeInfo.treeIndex].mesh;
for (int i = 0; i < trees[treeInfo.treeIndex].materials.Count; i++)
{
Material mat = trees[treeInfo.treeIndex].materials[i];
int batch = treeInfo.positions.Count / 1024;
for (int j = 0; j <= batch; j++)
{
int count = Mathf.Min(1023, treeInfo.positions.Count - j * 1024);
Graphics.DrawMeshInstanced(mesh, i, mat, treeInfo.positions.GetRange(j * 1024, count));
}
}
I tried calling it in Update, OnPreCull, OnSceneGUI. All had the same problem.