Graphics.DrawMesh not working

I tried rendering a cube with Graphics.DrawMesh on Unity 4.3, but nothing seems to happen. I have an empty scene with a camera looking at the origin. The following script is attached to the camera:

using UnityEngine;
public class DrawMesh : MonoBehaviour 
{	/* 5_ _ _6
      /|    /|
    1/_|_ 2/ |      
	| 4|_ _|_|7        
	| /    | / 
	|/_ _ _|/ 
    0      3 */
	Mesh mesh;

	void Start() {
		mesh = new Mesh();

		Vector3[] vertices  = new Vector3[] {
			new Vector3(-1, -1, -1),
			new Vector3(-1, +1, -1),
			new Vector3(+1, +1, -1),
			new Vector3(+1, -1, -1),
			
			new Vector3(-1, -1, +1),
			new Vector3(-1, +1, +1),
			new Vector3(+1, +1, +1),
			new Vector3(+1, -1, +1)};
		
		int[] triangles = new int[] {
			0, 1, 2,    2, 3, 0,
			1, 5, 6,    6, 2, 1,
			3, 2, 6,    6, 7, 3,
			4, 5, 1,    1, 0, 4,
			0, 3, 7,    7, 4, 0,
			7, 6, 5,    5, 4, 7};

		mesh.vertices = vertices;
		mesh.triangles = triangles;
		mesh.RecalculateNormals();
		mesh.RecalculateBounds();
	}

	void Update () {
		Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity);
	}
}

What am I doing wrong?

[18872-drawmesttest.zip|18872]

Graphics.DrawMesh should work pretty well if you:

  • actually use Graphics.DrawMesh and not Graphics.DrawMeshNow which is a totally different function.
  • have Unity pro since this is a pro feature. *It used to be a pro only feature.

DrawMeshNow will draw the mesh immediately. If you use this outside of a rendering callback it has no effect since it will get cleared when the actual rendering starts (which is at the end of each frame). DrawMesh on the other hand “registers” the mesh to be drawn this frame and it’s rendered when it’s time to do so.

edit
ps: You are aware of the fact that you can’t draw a cube with 8 vertices? Your “cube” will look like a lowpoly sphere. Each vertex can only have one normal vector. If you share all vertices like you did, RecalculateNormals will average the normal between all 3 faces that meet at the vertex. The difference is this:

cube normals

To render a cube like a cube you need at least 24 vertices or it will look like this:

smoothshaded cube

I’m a javascript user but, at the end of your triangles definition you have “7[};][1]” that looks odd. Try

int[] triangles = new int[] {
         0, 1, 2, 2, 3, 0,
         1, 5, 6,    6, 2, 1,
         3, 2, 6, 6, 7, 3,
         4, 5, 1, 1, 0, 4,
         0, 3, 7, 7, 4, 0,
         7, 6, 5, 5, 4, 7};