Duplicating a static mesh

Hi guys,

I need to duplicate a static mesh.

That is, I need the static mesh to have its own vertexbuffers so that they can be modified by instance (actually only colors are needed, but im guessing there would be no difference).

Is there a way to accomplish this?

Cheers,

There’s probably a better way, but you can grab FRawMesh data from your UStaticMesh and then create a new UStaticMesh from that FRawMesh.

Hmm. Im abit unsure what you mean. The only FRawMesh i see is editor only (#if WITH_EDITOR) and that also goes for FStaticMeshSourceModel in UStaticMesh?

After digging around in the code for a few mins it seems to me the best bet would be to add a duplicate to FStaticMeshRenderData and have it duplicate the buffers and set bInitialized to false. Then run void FStaticMeshRenderData::InitResources(UStaticMesh* Owner) again. Ofcourse this is adding functionality to the engine but i don’t really see another way.

Yeah I think it might be an editor only solution.

Hi ,

You could do it like this in 4.9:

FActorSpawnParameters SpawnParams;
SpawnParams.Name = FName( TEXT("MyDuplicate")));
SpawnParams.Template = OriginalMeshActor;
AStaticMeshActor* DuplicateMeshActor = GetWorld()->SpawnActorAbsolute<AStaticMeshActor>(OriginalMeshActor->GetClass(), OriginalMeshActor->GetTransform(), SpawnParams);

Franco