Non-Dynamic Instanced Static Meshes broken in package builds

I have found a bug with instanced static meshes rendering incorrectly in package builds after upgrading to 4.17.

We are spawning new instances at runtime using AddInstanceWorldSpace on a UInstancedStaticMeshComponent with UseDynamicInstanceBuffer set to false (default). Changing this to true fixes the problem. In the Editor, all instanced static meshes are dynamic, so the problem isn’t seen.

I managed to track this down to FStaticMeshInstanceBuffer::SetupCPUAccess where the IsDynamic flag is used to set AllowCPUAccess to true. As a work around, I have copied the following line from FStaticMeshInstanceBuffer::InitFromPreallocatedData to FStaticMeshInstanceBuffer::Init:

InstanceData->SetAllowCPUAccess(true); // GDC demo hack!

As the comment suggests, this is a bit hacky, so looks like there’s an underlying problem with not allowing CPU access to be addressed.

This is already fixed in 4.17.2 or in 4.18 Preview 3

I’ve checked 4.17.2 and it’s not fixed there, so perhaps 4.18 addresses it.