I want to traverse all triangles of a static mesh:
UStaticMeshComponent const* StaticMeshComp;
FPositionVertexBuffer const& vertexBuffer = StaticMeshComp->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer;
FIndexArrayView IndexBuffer = StaticMeshComp->GetStaticMesh()->RenderData->LODResources[0].IndexBuffer.GetArrayView();
uint32 const numberTriangles = StaticMeshComp->GetStaticMesh()->RenderData->LODResources[0].GetNumTriangles();
int i, j;
// get vertex j (= 0, 1, 2) of face i (= 0, ..., numberTriangles - 1)
FVector vertex = vertexBuffer.VertexPosition(IndexBuffer[3*i + j]);
You have to enable “Allow CPUAccess” on all static meshes that you want to examine this way, otherwise this only works in PIE and not in a packaged build.
But it does not work in a packaged dedicated server (“invalid access”). Interestingly, when I copy-paste the cooked mesh from client package to dedicated-server package, it works. Anyway, I don’t like this dirty workaround.
So, how do you access the vertices and meshes on a dedicated server?