How can I access vertex buffer of a mesh in runtime correctly?

I making a own physics engine. but I found a critical problem that making a convex collision from imported static mesh. First, here is my code.

	void UFPXConvexShape::SetConvexFromStaticMesh(const UStaticMesh* pMesh, const int pLodGroup)
	{
		FPX_LOG(== == == SetConvexFromStaticMesh);
		check(nullptr != pMesh);
		const TIndirectArray<FStaticMeshLODResources>& lLodResources = pMesh->RenderData->LODResources;
		check(lLodResources.IsValidIndex(pLodGroup));
		const FStaticMeshLODResources& lResource = lLodResources[pLodGroup];
		lResource.IndexBuffer.GetCopy(mVertexIndices);
		// Inverse Triangle Order.
		for (int32 i = 0; i < mVertexIndices.Num(); i += 3)
		{
			FPX_SWAP(mVertexIndices[i], mVertexIndices[i + 2]);
		}
		const FPositionVertexBuffer& lVertexBuffer = lResource.PositionVertexBuffer;
		const uint32 lCount = lVertexBuffer.GetNumVertices();
		check(3 < lCount);
		mVertices.Empty(lCount);
		for (uint32 i = 0; i < lCount; i++)
		{
			const FVector& lSrc = lVertexBuffer.VertexPosition(i);
			FPX_LOG_VECTOR(Vertex, SFPXVector(lSrc));
			mVertices.Add(SFPXVector(lSrc));
		}

I accessed vertex buffer by LODResources. It works great in game preview. but odd value obtained in packaged game or built game with Development config. You can download above logs here. (ok.txt is logged in DebugGame Editor, error.txt in Development.) I think, cooked asset occur this problem. If right, how can I access correctly. otherwise, how can I fix that?

Thanks!

The problem is not solved. Does anyone know about this?

What dependencies do you have to be able to get the PositionVertexBuffer? I’m not able to access it without triggering a linker error.

@Omberone

#StaticMeshResources

You need this:

//Static Mesh Vertex buffer
#include "StaticMeshResources.h"

#I can Confirm The Issue

I also access the vertices of static meshes in packaged game, and I can confirm that I get weird results that I presume are due to cooking.

I tested this in 4.3, was hoping it was resolved in 4.5

Some meshes are fine, but some have their vertices all jumbled an weird.

I am using PositionVertexBuffer in packaged game.

Rama

Did you find a solution to this? I am using enqueue unique render commands to get the Index Buffer and the Vertex Positions. All the data is there but I cannot seem to make any sense of it.

Maybe the index buffer integers are not organized the same as when GetArrayView() is used so using the indices to get the triangle vertices doesn’t give the correct index.

It is 4.22 and still no luck.
Can any staff answer this issue?

In order to do this types of access in the packaged build you need to set the Allow CPU Access on the Static Mesh You are using as UE, when packaging builds does some sort of optimization and keeps static meshes only on the GPU, unless Allow CPU Access is specified.

2 Likes

Thanks. This solved crashes in shipping build for me.