How to get the vertex position through the face index

Hi,
I want to get the face information of the static mesh through the “Line Trace by Channel” method, and then use this face to retrieve the vertex data on that face. Is it possible to achieve this? And how should we do it?

Yes. Face Index on the hit is the triangle, and that triangle’s three indices are the vertices. It stays -1 unless the trace is complex.

On Line Trace by Channel, turn Trace Complex on. Face Index is only filled for per-triangle traces. A simple-collision trace has no face.

That index is into the mesh you actually traced. If complex collision was auto-generated, it is not the render mesh, so the corners will not match the visible triangles. For a 1:1 match, set Collision Complexity to Use Complex Collision As Simple and read LOD 0. Nanite does not keep a normal LOD 0 index buffer you can index this way, so disable Nanite on that asset, or read the complex collision mesh instead of the render LOD.

Blueprint can Break Hit Result and read Face Index, but it cannot read the index buffer. The positions need a small function on the game thread:

const FStaticMeshLODResources& LOD = Mesh->GetRenderData()->LODResources[0];
const FIndexArrayView Indices = LOD.IndexBuffer.GetArrayView();
const int32 Base = Hit.FaceIndex * 3;
if (Base < 0 || Base + 2 >= Indices.Num())
{
    return;
}

const FPositionVertexBuffer& Positions = LOD.VertexBuffers.PositionVertexBuffer;
const FTransform& Xf = Component->GetComponentTransform();
FVector World[3];
for (int32 i = 0; i < 3; ++i)
{
    const uint32 Index = Indices[Base + i];
    World[i] = Xf.TransformPosition(FVector(Positions.VertexPosition(Index)));
}

Do not touch render data while the mesh is still compiling. If you only need a point on the surface and not the three corners, Hit.ImpactPoint is already that point.