Access mesh vertices on dedicated server package

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?

Also need this answered.

When you say “copy-paste the cooked mesh from client package to dedicated-server package” can you give an example of the file(s) to be copied? How do you know the names of all the files you need to copy?

You have to copy all the files belonging to the mesh where you have enabled “Allow CPUAccess”.
For example ClientGameFolder/ProjectName/Content/path/to/SpecificMesh.uexp.

I am not sure if only the uexp files or also uasset. Just copy all files that are significantly bigger in client version than in the dedicated server version.

thanks for the reply. that did work and fixes my issue for now…

Hey, sorry for the bump on an old thread, but did you ever figure out a cleaner solution than just copying the assets/pak file/s over from the client build?