Problem with RaycastHit not returning correct triangle index

I’ve attached an example project for a simple MeshCollider.Raycast against a plane.

I have verified the RaycastHit.point returned is correct.

However, the triangleIndex is not being returned correctly.

Any suggestions?

I wanted to show the RaycastHit.position is correct by placing a cube.

The RaycastHit.triangleIndex seems to have an issue…

112769--4330--$raycasthittriangleindex_153.jpg
112769–4331–$raycast004_695.zip (481 KB)

The documentation provides a workaround to convert the local vertex position into world space:

This does not however, retrieve the triangleIndex that I’m trying to get.

What is the triangleIndex for if not the mesh.triangle index?

112775--4333--$raycasthittriangleindex2_172.jpg

_FaceIndex = raycastHit.triangleIndex;

should be

_FaceIndex = raycastHit.triangleIndex*3;

–Eric

I see that would be consistent with the picture. I should have realized these could be triangle strips.

112818–4335–$raycast005_448.zip (482 KB)
112818--4336--$raycasthittriangleindex3_192.jpg

I had the same problem with picking the triangle with the Mouse .Multiplication by 3 solved it.However now I am struggling with additional problem.I want tot achieve very simple task:when the mouse hits the triangle I need it to disappear completely.Currently I am doing something like this:

for(int i=0;i<origTriangles.Length;++i){
			if(origTriangles[i]!=selectedTriIndex){
				
				newVerts[i]=origVertices[origTriangles[i]];
				newUV[i]=origUV[origTriangles[i]];
				newNormals[i]=origNormals[origTriangles[i]];
				newTriangles[i]=i;
			
			}	else{
				
				//here I do nothing but also tried to set vertices vectors to zero and also nullify uvs ,ets
                              ////it did not work 
                              ////???
			}
		}

So origTriangles are the triangles of the whole sphere,selectedTriIndex is the RaycastHit triangleIndex*3 .In the loop I check when the hit triangle is one that is currently in the loop ,if it is not so I refill back the geometry and update my sphere back after the end of the loop.IN this case the "deleted " triangles are concentrating towards world’s 0,0,0 but they don’t disappear .

Appreciate any help

Array.ToList().RemoveAt(IndexOf(hit.triangleIndex3+0));
Array.ToList().RemoveAt(IndexOf(hit.triangleIndex
3+1));
Array.ToList().RemoveAt(IndexOf(hit.triangleIndex*3+2));