- Home /
Getting the triangles (not setting) of statically batched meshes?
Is it possible to get the triangles of a mesh for raycast checking if that mesh is static and has been batched? I'm using the following code
public static int submeshIndexOfTriangle(Mesh refMesh, int triangleIndex) {
for(int i = 0; i < refMesh.subMeshCount; i++) {
int[] tris = refMesh.GetTriangles(i);
for(int u = 0; u < tris.Length; u++) {
if (u == triangleIndex)
return i;
}
}
return -1;
}
to try and get the submesh index of a triangle that a raycast hit to check its material but I get the error
Not allowed to access triangles/indices on mesh 'Combined Mesh (root: scene)' (isReadable is false; Read/Write must be enabled in import settings)
when I try to access the triangles; this, of course, is because the statically batched aggregate mesh does not have read/write enabled. What would be my best solution for fixing this problem?
Comment