Unity doesn't display runtime generated mesh

Hey there.

I generate a mesh at runtime. When I assign vertices, normals and indices (triangles) to my mesh, and call RecalculateBounds, it returns center: (0,0,0) extents: (0,0,0) and I cannot see my object.

So, I’ve tried exporting my data to .obj format and loading it up in various viewers.
I’ve tried blender and two online 3D model viewers and my model was loaded up and displayed correctly.

Then, I’ve tried to load up that generated .obj file to Unity, and it, too, did display it correctly (but as I guess it did some changes to it).

My question is- what could be wrong, and how could I fix it? What changes does Unity commit to my file so that it is able to display it?

Post code bra

It’s too complex :confused:

#Edit
I am binding most functions from C DLL, so it looks like this:

var omesh = new Mesh();
var vertices = Bindings.GetVertices();
var vertices_size = Bindings.GetVerticesSize();
var indices = Bindings.GetIndices();
var indices_size = Bindings.GetIndicesSize();
omesh.vertices = new Vector3[vertices_size];
for(int i = 0; i < vertices_size; i++) {
        float x = Bindings.Vertices_getXAt(vertices, i);
        float y = Bindings.Vertices_getYAt(vertices, i);
        float z = Bindings.Vertices_getZAt(vertices, i);
        omesh.vertices[i] = new Vector3(x,y,z);
        x = Bindings.Vertices_getNormalXAt(vertices, i);
        y = Bindings.Vertices_getNormalYAt(vertices, i);
        z = Bindings.Vertices_getNormalZAt(vertices, i);
        omesh.normals[i] = new Vector3(x,y,z);
}
omesh.triangles = new Vector3[indices_size];
for(int i = 0; i < indices_size; i++) {
       omesh.triangles[i] = Bindings.GetTriangle(indices, i);
}

GetComponent<MeshFilter>().mesh = omesh;

Doesn’t show how the vertices and indices are generated (that’s thousands of lines…), but it’s something.

Do you have a Mesh Renderer component on your Game Object?

Good thing you posted some code bra

“Returns a copy of the vertex positions or assigns a new vertex positions array.”
So on line 16 you are just changing the value in an array that doesn’t actually apply to anything.
Probably the same on line 20

You must get the arrays (a copy) and assign to a variable
Work on that variable
Then assign the arrays back to mesh.verts & triangles