How can I find if a line intersects a triangle?

I need to figure out if a line intersects a triangle. I’ve looked through the FMath section and I cannot find anything that works. I want to be able to pick a face from my container and use the three FVectors it references, then compare that with a ray (2 FVectors) and see if this ray is inside the triangle (where it penetrates the triangle)

I’m trying to figure out which face index on my procedural mesh (component) is being hit or specifically my character is standing on. So my ray hits the procedural mesh, but I don’t think there is a way to get the face index from the rayhit so I’m using the container from where the proc mesh was built from. This houses all the vert locations. What I want to do is use three FVectors (the triangle being tested) and the ray (my characters location) and see if the ray is inside the triangle. This will let me know which face index is being hit. My faces are organized into subdivision levels so the lowest subD is tested first (because it has very few triangles) then it steps up the subdivision locally to quickly find which higher resolution face is being hit. Problem is I can’t find a function to tell me if my ray is intersecting a triangle I provide…

have you tried line traces?

FHitResult has a FaceIndex

FCollisionQueryParams has a member called bReturnFaceIndex, which probably defaults to false for performance, because that granularity is usually not needed.

so try this in your tracing:

FCollisionQueryParams TraceParams(blah, blah, blah)
TraceParams.bTraceComplex = true;
TraceParams.bReturnFaceIndex = true;

I would like to be able to use three FVectors to define a triangle, and 2 FVectors to define a ray. And check to see if the ray intersects the triangle.

Yeah but that isn’t the actual face index. Link Or maybe I’m reading this wrong, but it sounds like if you’re using a triangle mesh for the search query? Does that mean the ray is a triangle mesh or the triangle it is hitting?

Hmm when using LineTraceSingle_New my trace hits the procedural mesh, but when I use LineTraceSingleByChannel it doesn’t. The problem here is that I can turn on TraceParams.bReturnFaceIndex = true; using the single by channel, but I can’t using the linetracesingle_new. There’s no way to give trace params to the _new version, but there is with the by channel version, but it doesn’t hit the procedural mesh. Even if I turn on bTraceComplex (because my procedural mesh uses that)

Okay so that worked. Problem is I was hitting my character with the LineTraceSingleByChannel. I wasn’t ignoring that actor in the trace. It now returns the face index from the trace! This saved me a headache. Thanks a bunch!

Hi, I have meeting the same trouble. after read you work. I want to konw how to get the material of the static mesh by triangle index?

This sounds like what you’re looking for. LINK. You need to set bReturnPhysicalMaterial to true on the FCollisionQueryParams, then you should be able to get the material directly from the FHitResult.