Hello.
As I said in the title, I need to create a copy of a static mesh in C++. Which is the best way to do this? I’m loading the static mesh in this way:
static ConstructorHelpers::FObjectFinder<UStaticMesh> cargadorModelo(TEXT("/Game/Modelos/basico_mm"));
UStaticMesh* modelo;
if (cargadorModelo.Succeeded()){
modelo = cargadorModelo.Object;
}
Is important to do that copy because following this code, I edit some properties in the RawMesh, and when I build the mesh for see the changes and associate this mesh as a subobject of the actor, I change the original mesh, and this is not what I want, because it’s a process I must do more than one time on the original mesh.
Thank you.
Solution:
static ConstructorHelpers::FObjectFinder<UStaticMesh> cargadorModelo(TEXT("/Game/Modelos/basico_mm"));
UStaticMesh* modelo;
if (cargadorModelo.Succeeded()){
modelo = cargadorModelo.Object;
}
else {
// error code
}
if (!modelo->IsValidLowLevel()){
// error code
}
if (&modelo->SourceModels[0] == nullptr){
// error code
}
// Get raw information of the model
FStaticMeshSourceModel* sourceModel = &modelo->SourceModels[0];
FRawMesh rawMesh;
sourceModel->RawMeshBulkData->LoadRawMesh(rawMesh);
// Create a new model
UStaticMesh* modeloNuevo = NewObject<UStaticMesh>();
new(modeloNuevo->SourceModels) FStaticMeshSourceModel();
modeloNuevo->SourceModels[0].RawMeshBulkData->SaveRawMesh(rawMesh);
TArray<FText> BuildErrorsNuevo;
modeloNuevo->Build(true, &BuildErrorsNuevo);