IndexBuffer empty in Cooked Version

Hi,
I have some C++ Code that reads the Triangles of a static mesh. It uses the IndexBuffer and PositionVertexBuffer from the LODResource (Mesh->GetStaticMeshComponent()->StaticMesh->RenderData->LODResources[0]). In the Editor-Version all is fine but in DebugGame, Development or Shipping Build the IndexBuffer is empty. I can see that there are 53504 Tris with 28744 Vertices. Where I can get the Indices to get the Triangles?

Edit: I see the bNeedsCPUAccess flag is false in the Buffer. Can this be the problem? How can I set it to true?

I found a solution:
In Editorbuilds the data is cached at RAM, but in Cooked builds the data is only at VRAM. So I have to lock the buffer to get the data.

int numIndices = pLODResource.IndexBuffer.IndexBufferRHI->GetSize() / sizeof(uint16);
uint16* Indices = new uint16[numIndices];
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
	GetIndexBuffer,
	FRawStaticIndexBuffer*, IndexBuffer, &pLODResource.IndexBuffer,
	uint16*, Indices, Indices,
	{
		uint16* indices = (uint16*)RHILockIndexBuffer(IndexBuffer->IndexBufferRHI, 0, IndexBuffer->IndexBufferRHI->GetSize(), RLM_ReadOnly);
		memcpy(Indices, indices, IndexBuffer->IndexBufferRHI->GetSize());
		RHIUnlockIndexBuffer(IndexBuffer->IndexBufferRHI);
	});

The same thing I did with the vertex buffers I needed.

Ran into this same problem and your solution works beautifully. Thanks!

This looks like what I need! Thanks!
One quick question I want to get this indices value into blueprints but have ran into a few problems. As I understand it scheduling something on the render thread like this is asynchronous so when I return Indices and call it from a blueprint I get garbage values.
So my question is, is there any way to turn the ENQUEUE into a blocking function/wait for it to finish or am I thinking about it all wrong and need to use some callback/event delegate system?

You can call FlushRenderingCommands() after the enqueue then the main thread is blocked until the render thread has executed the command.
If you don’t want to block the thread you have to wait until the next frame. But I don’t know how to implement this in blueprints.

Brilliant! thanks, one more question, what would be the best way to wait for the next frame in c++ then? I guess you could use a timer but that uses seconds not frames or maybe some sort of gate in the actor tick?

Thanks for the post. I was wondering if there was any pointers you could give to get this to work for a position vertex buffer. I went through it for a while and tried several permutations but couldn’t get the packaged build running.

Are you still using this? I haven’t been able to get it to work. I’m trying to get the Array View from the Index buffer.

To fix this problem at least with static meshes, put “Allow cpu access” tick in the mesh editor.