# Copying a static mesh in c++

**URL:** <https://forums.unrealengine.com/t/copying-a-static-mesh-in-c/350661>\
**Category:** Asset Creation\
**Tags:** copy, unreal-engine, CPP, question\
**Created:** [March 15, 2016, 11:12pm UTC](https://forums.unrealengine.com/t/copying-a-static-mesh-in-c/350661 "2016-03-15T23:12:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_74e323db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_74e323db](https://forums.unrealengine.com/u/anonymous_user_74e323db)\
**Post date:** [March 15, 2016, 11:12pm UTC](https://forums.unrealengine.com/t/copying-a-static-mesh-in-c/350661/1 "2016-03-15T23:12:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_74e323db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_74e323db](https://forums.unrealengine.com/u/anonymous_user_74e323db)\
**Post date:** [April 23, 2016, 4:14am UTC](https://forums.unrealengine.com/t/copying-a-static-mesh-in-c/350661/2 "2016-04-23T04:14:59Z")

</div>

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);

```
