# Static mesh built in cpp called in editor is not visible

**URL:** <https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, Scripting, question\
**Created:** [May 25, 2022, 5:48pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371 "2022-05-25T17:48:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matrem84](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matrem84](https://forums.unrealengine.com/u/matrem84)\
**Post date:** [May 25, 2022, 5:48pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371/1 "2022-05-25T17:48:43Z")

</div>

I try to build a static mesh in a function library called from an editor tool blueprint.  
But I can’t get my static mesh to be visible. Do I miss something ?

```cpp
	auto actor = world->SpawnActor<AActor>();
	actor->SetActorLabel(TEXT("Terrain"));

	UStaticMeshComponent * mesh_component = NewObject<UStaticMeshComponent>(actor, FName(TEXT("Mesh")));

	actor->SetRootComponent(mesh_component);

	FMeshDescription mesh_desc;

	FStaticMeshAttributes attributes(mesh_desc);
	attributes.Register();

	TVertexAttributesRef<FVector3f> positions = mesh_desc.GetVertexPositions();

	mesh_desc.ReserveNewVertices(4);
	FVertexID v0 = mesh_desc.CreateVertex();
	FVertexID v1 = mesh_desc.CreateVertex();
	FVertexID v2 = mesh_desc.CreateVertex();
	FVertexID v3 = mesh_desc.CreateVertex();
	
	mesh_desc.ReserveNewVertexInstances(4);
	FVertexInstanceID vi0 = mesh_desc.CreateVertexInstance(v0);
	FVertexInstanceID vi1 = mesh_desc.CreateVertexInstance(v1);
	FVertexInstanceID vi2 = mesh_desc.CreateVertexInstance(v2);
	FVertexInstanceID vi3 = mesh_desc.CreateVertexInstance(v3);

	mesh_desc.ReserveNewUVs(4);
	FUVID uv0 = mesh_desc.CreateUV();
	FUVID uv1 = mesh_desc.CreateUV();
	FUVID uv2 = mesh_desc.CreateUV();
	FUVID uv3 = mesh_desc.CreateUV();

	FPolygonGroupID polygon_group = mesh_desc.CreatePolygonGroup();

	mesh_desc.ReserveNewPolygons(1);
	mesh_desc.CreatePolygon(polygon_group, {vi0, vi1, vi2, vi3});

	positions = attributes.GetVertexPositions();

	positions[0] = FVector3f(-100, -100, 0);
	positions[1] = FVector3f(100, -100, 0);
	positions[2] = FVector3f(100, 100, 0);
	positions[3] = FVector3f(-100, 100, 0);

	TVertexInstanceAttributesRef<FVector3f> normals = attributes.GetVertexInstanceNormals();

	normals[0] = FVector3f(0, 0, 1);
	normals[1] = FVector3f(0, 0, 1);
	normals[2] = FVector3f(0, 0, 1);
	normals[3] = FVector3f(0, 0, 1);

	TVertexInstanceAttributesRef<FVector2f> uvs = attributes.GetVertexInstanceUVs();

	uvs[0] = FVector2f(0, 0);
	uvs[1] = FVector2f(1, 0);
	uvs[2] = FVector2f(1, 1);
	uvs[3] = FVector2f(0, 1);

	mesh_desc.TriangulateMesh();

	// At least one material must be added
	UStaticMesh* mesh = NewObject<UStaticMesh>(actor, FName(TEXT("ProceduralStaticMesh")));
	mesh->GetStaticMaterials().Add(FStaticMaterial());

	UStaticMesh::FBuildMeshDescriptionsParams mdParams;
	mdParams.bBuildSimpleCollision = true;
	//mdParams.bFastBuild = true;

	// Build static mesh
	mesh->BuildFromMeshDescriptions({&mesh_desc}, mdParams);
	
	mesh_component->SetStaticMesh(mesh);

```

---

<div class="post-metadata">

**Author:** ![matrem84](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matrem84](https://forums.unrealengine.com/u/matrem84)\
**Post date:** [May 25, 2022, 7:00pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371/2 "2022-05-25T19:00:34Z")

</div>

Strangely if I save my scene and restart, the static mesh becomes visible.  
Is there something to call to refresh something in the editor?

---

<div class="post-metadata">

**Author:** ![matrem84](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matrem84](https://forums.unrealengine.com/u/matrem84)\
**Post date:** [May 25, 2022, 8:43pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371/3 "2022-05-25T20:43:10Z")

</div>

Perhaps this can help undestand :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/3/d/93d6fceb81826711719a926b44e915dfab3801c6.png)  
The mesh details is completly grey out, so I can not even edit the static mesh to debug it.

If I duplicate it, the duplicata is editable … 😛

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/3/7/037eea51d418cd0563b81702a11720bce11bd457.jpeg)

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [May 25, 2022, 8:46pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371/4 "2022-05-25T20:46:29Z")

</div>

I’m not sure, but don’t you have to Register() the component if you create it in runtime? I see you Register() attributes, but not mesh\_component.  
It might not be the case, I’m just speculating.

---

<div class="post-metadata">

**Author:** ![matrem84](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matrem84](https://forums.unrealengine.com/u/matrem84)\
**Post date:** [May 25, 2022, 9:19pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371/5 "2022-05-25T21:19:52Z")

</div>

I think the register of FStaticMeshAttributes has nothing to do with the one of component, but your are right, it seems to be very important to call RegisterComponent on dynamically created components!  
Thanks.  
So one problem stay, I cant edit the static mesh component content, everything is grey out with the property warning.

---

<div class="post-metadata">

**Author:** ![matrem84](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matrem84](https://forums.unrealengine.com/u/matrem84)\
**Post date:** [May 25, 2022, 9:30pm UTC](https://forums.unrealengine.com/t/static-mesh-built-in-cpp-called-in-editor-is-not-visible/566371/6 "2022-05-25T21:30:12Z")

</div>

mesh\_component-\>CreationMethod = EComponentCreationMethod::Instance (perhaps native is best for my case)  
before the RegisterComponent seems to do the job to get it editable.
