- Home /
CombineMeshes Error on Run-time Meshes
I'm attempting to combine the meshes of a few Game Objects generated at run-time. The meshes are generated with Leap Motion's Pinch Draw script. This is the function I'm using to combine them:
void MergeLineObjects()
{
GameObject noteContainer = GameObject.FindWithTag("AnnotationContainer");
MeshFilter[] meshFilters = noteContainer.GetComponentsInChildren<MeshFilter>();
Mesh finalMesh = new Mesh();
CombineInstance[] combineInstances = new CombineInstance[meshFilters.Length];
for(int i = 0; i < meshFilters.Length; i++)
{
meshFilters[i].sharedMesh.Optimize(); //Might not do anything
combineInstances[i].subMeshIndex = 0;
combineInstances[i].mesh = meshFilters[i].sharedMesh;
combineInstances[i].transform = meshFilters[i].transform.localToWorldMatrix;
}
finalMesh.CombineMeshes(combineInstances); // Getting error: Cannot combine mesh that does not allow access: Line Mesh
meshFilters[0].sharedMesh = finalMesh;
meshFilters[0].gameObject.SetActive(true);
}
}
When running this, I get the error: Cannot combine mesh that does not allow access: Line Mesh
None of the mesh objects are static, and my function is basically following the example for CombineMeshes() in the Unity Documentation. Has anyone else run into this?
Thank you!
Answer by WalkupAndAway · Jan 11, 2017 at 10:38 PM
Solved this!
Within Leap Motion's Pinch Draw script, there is a function called FinishLine() that completes the generation of the user-drawn mesh. Within that function, they used the mesh function UploadMeshData() with the parameter 'markNoLongerReadable' set to 'true', meaning that data could not be read from the mesh after it was created.
This was preventing the meshes from being combined, and simply changing the value of the 'markNoLongerReadable' parameter to 'false' fixed the issue!
The code before:
public void FinishLine() {
_mesh.Optimize();
_mesh.UploadMeshData(true);
}
The code after:
public void FinishLine() {
_mesh.Optimize();
_mesh.UploadMeshData(false);
}
Easy as that!
Answer by unity_l3Ac7R_V3zAEkQ · Nov 20, 2018 at 05:00 AM
where i can call FinishLine() Function . Please Explain Clearly.