I have hit a strange bug I don’t know if it’s feature. I want to create meshes and I need to combine various part together, to test the implementation I started with a very simple project.
Here is the code:
this.plane = GetComponent<MeshFilter>().mesh;
this.plane.Clear ();
this.plane.name = "plane";
CombineInstance[] cube = new CombineInstance[6];
cube [0].mesh = MeshGenerator.createPlane (MeshGenerator.axis.top ,1);
cube [1].mesh = MeshGenerator.createPlane (MeshGenerator.axis.bottom,1);
cube [2].mesh = MeshGenerator.createPlane (MeshGenerator.axis.front ,1);
cube [3].mesh = MeshGenerator.createPlane (MeshGenerator.axis.back ,1);
cube [4].mesh = MeshGenerator.createPlane (MeshGenerator.axis.side1 ,1);
cube [5].mesh = MeshGenerator.createPlane (MeshGenerator.axis.side2 ,1);
this.plane.CombineMeshes (cube,true);
this.gameObject.GetComponent<MeshFilter>().mesh = this.plane;
It’s in the start method and the mesh don’t show up … ![]()
TO debug I add these lines at the end:
Debug.Log (this.plane.vertexCount);
Debug.Log (this.gameObject.GetComponent<MeshFilter>().mesh.vertexCount);
Which return correct data
… I add mark dynamic and the recalculates:
this.plane = GetComponent<MeshFilter>().mesh;
this.plane.Clear ();
this.plane.name = "plane";
this.plane.MarkDynamic ();
CombineInstance[] cube = new CombineInstance[6];
cube [0].mesh = MeshGenerator.createPlane (MeshGenerator.axis.top ,1);
cube [1].mesh = MeshGenerator.createPlane (MeshGenerator.axis.bottom,1);
cube [2].mesh = MeshGenerator.createPlane (MeshGenerator.axis.front ,1);
cube [3].mesh = MeshGenerator.createPlane (MeshGenerator.axis.back ,1);
cube [4].mesh = MeshGenerator.createPlane (MeshGenerator.axis.side1 ,1);
cube [5].mesh = MeshGenerator.createPlane (MeshGenerator.axis.side2 ,1);
this.plane.CombineMeshes (cube,true);
this.plane.RecalculateBounds();
this.plane.RecalculateNormals();
this.plane.RecalculateTangents();
this.gameObject.GetComponent<MeshFilter>().mesh = this.plane;
Debug.Log (this.plane.vertexCount);
Debug.Log (this.gameObject.GetComponent<MeshFilter>().mesh.vertexCount);
And nothing show up
… I move the code to update and nothing show up
… I had this line after assigning the meshfilter:
this.gameObject.GetComponent<MeshFilter>().mesh = MeshGenerator.createPlane (MeshGenerator.axis.top,1);
And it return a plane showing correctly as expected
…
I’m at loss of options :(, did someone met such a problem before? How I do solve this? Is it just me who is dumb
and miss something?
