Mesh created in code is not visible

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

mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 100, 0), new Vector3(100, 100, 100)};
mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)};
mesh.triangles = new int[] { 0,1,2 };

gameObject.AddComponent<MeshRenderer>();
gameObject.AddComponent<MeshFilter>().mesh=mesh;

}

I can’t see my mesh :confused: Why?
Camera is set to 0,0,-64 with no rotation

You might need to do this. Unity may not see that the bounds of your mesh are within the view frustum, so it’s getting culled.

http://unity3d.com/support/documentation/ScriptReference/Mesh.RecalculateBounds.html

No one had right.

The problem was there:

mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 100, 0), new Vector3(100, 100, 100)};

I’ve changed verticles to

new Vector3[] {new Vector3(0, 0, 0), new Vector3(100, 0, 0), new Vector3(100, 100, 0),new Vector3(0,100,0)};

and saw a beautyfull mesh ;].And right,it is also visible after switch from game to scene view.
It’s a mystery why you could see previous mesh,while I can’t…but the issue is solved anyway.

Thank the all answerers for clues :slight_smile:

I had a similar problem and it took me a little while to figure out what was going on. I would run the program, and look for my generated plane in the scene. I could see the object in the scene object list, and select it there, and the handle for it would show up in the scene window, but it seemed that no matter how I oriented the view I could not see the plane. Not even the visual representation of the geometry for it.

At some point I realized that for some reason during some prior work I had set the “layers” setting in the IDE environment (upper right corner, in 3.5) to “nothing” so that it would only show the gizmo and such for object I had selected in the scene object list. (I had been away from using Unity for a little while, and in this new scene I had almost nothing in the scene, so, the fact that that was set that way wasn’t… just immediately obvious. Should’ve been, but it wasn’t to me at the time.)

After switching the “layers” setting to “default” or to “everything”, and then reorienting the view, I could see my plane when looking at it from “behind” (as I was thinking of it), which meant, of course, that the triangle’s vertices ran counter-clockwise when viewed from what I was thinking of as being the “front.”

When I examined the definitions for the points carefully and thought about them from the angle I was expecting to be able to see them from, I realized, gosh, they were counter- clockwise. Duh. So when my code was making the calculate normals call, it inverted them in comparison to what I was expecting, so the view was simply culling back faces.

I’m not sure why I could not even see my plane in the scene view even when I had it selected and was looking at it from “behind”. I notice that when you have the “layers” setting set to “nothing,” the scene window only shows geometry, it doesn’t show textures, and it only shows the geometry of the currently selected object, so maybe that’s what threw me off. Maybe I just never had it selected in the scene object list when I was orienting the view correctly in order to be able to see it.