Problems with Graphics.DrawMesh, where to call it and how to get material property blocks to work.

I've been trying to use Graphics.DrawMesh to improve the performance of drawing multiple instances of a mesh and have run into some issues.

Based on the documentation I first tried to call Graphics.DrawMesh in the OnRenderObject method which didn't work. Putting it in the Update method instead solved the problem but is that really the proper location of calls to Graphics.DrawMesh?

Another issue is that modifying shader parameters between Graphics.DrawMesh calls using material property blocks doesn't appear to work. It looks like the material property block of the first visible instance of the mesh will get used by all other instances of the mesh, even if each draw call uses a different material property block.

Can somebody provide an example of working code that renders two or more instances of a mesh and applies different material property blocks to each instance?

Here's a (simplified) C# version of my Update method:

Graphics.DrawMesh( mesh, matrix0, material, 0, null, 0, propertyBlock0, false, false ); Graphics.DrawMesh( mesh, matrix1, material, 0, null, 0, propertyBlock1, false, false );

`DrawMesh` doesn't execute the rendering immediately so it doesn't really matter where you put it (I use lateupdate for several reasons but in update is fine). As the renderering isn't executed at call time, modifying materials between calls doesn't work (it takes the material at time of rendering so probably the final state). It sounds like you need to use `Graphics.DrawMeshNow`.

Like Jaap said, Graphics.DrawMesh does not render the mesh immediately. So it does not really matter where you put it; it will be eventually drawn in that frame.

I just found out that indeed, using MaterialPropertyBlock works funny with per-pixel lit shaders (or perhaps all multipass shaders). If I use VertexLit shader (or any other single pass shader) on the objects, then it works correctly for me.

I'm trying to use the DrawMesh code in my game but objects which I try to render using it don't light properly. See my other thread on the topic: http://forum.unity3d.com/viewtopic.php?t=53159

Can anyone advise why this might be? To summarise objects which i try to render using hte DrawMesh code light overbright on faces which face the directional light in the scene which i am using for the sun. If I render the same object using the normal rendering code they light perfectly. I'm at a loss to understand why this might be and would like to fix it.

thank you in advance,

Tony Oakden