# How modify vertex in static mesh? c++

**URL:** <https://forums.unrealengine.com/t/how-modify-vertex-in-static-mesh-c/471175>\
**Category:** Rendering\
**Tags:** vertex, vertex-position, unreal-engine, UE4, CPP, question\
**Created:** [September 14, 2020, 6:37am UTC](https://forums.unrealengine.com/t/how-modify-vertex-in-static-mesh-c/471175 "2020-09-14T06:37:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_474e99ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_474e99ad](https://forums.unrealengine.com/u/anonymous_user_474e99ad)\
**Post date:** [September 14, 2020, 6:37am UTC](https://forums.unrealengine.com/t/how-modify-vertex-in-static-mesh-c/471175/1 "2020-09-14T06:37:43Z")

</div>

Hello everyone! How i can modify vertex in static mesh using c++? I have c++ code to get the position of vertex, but i cant understand how modify vertex in realtime.

```
TArray<FVector> ADoorModify::MeshData(const UStaticMeshComponent* StaticMeshComponent)
    {
    	TArray<FVector> vertices = TArray<FVector>();
    
    
    	// Vertex Buffer
    	if (!IsValidLowLevel()) return vertices;
    	if (!StaticMeshComponent) return vertices;
    	if (!StaticMeshComponent->GetStaticMesh()) return vertices;
    	if (!StaticMeshComponent->GetStaticMesh()->RenderData) return vertices;
    
    	if (StaticMeshComponent->GetStaticMesh()->RenderData->LODResources.Num() > 0)
    	{
    		//PositionVertexBuffer
    		FPositionVertexBuffer* VertexBuffer = &StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer;
    		FStaticMeshVertexBuffer* StaticMeshVertexBuffer = &StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.StaticMeshVertexBuffer;
    		 FStaticMeshBuildVertex* StaticMeshBuildVertex;
    		StaticMeshBuildVertex->Position = FVector(0, 0, 0);
    	//	StaticMeshVertexBuffer->AppendVertices(StaticMeshBuildVertex,1);
    		//&StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers 
    		if (VertexBuffer)
    		{
    			const int32 VertexCount = VertexBuffer->GetNumVertices();
    			for (int32 Index = 0; Index < VertexCount; Index++)
    			{
    				//This is in the Static Mesh Actor Class, so it is location and tranform of the SMActor
    				const FVector WorldSpaceVertexLocation = GetActorLocation() + GetTransform().TransformVector(VertexBuffer->VertexPosition(Index));
    				//add to output FVector array
    				vertices.Add(WorldSpaceVertexLocation);
    				const FVector test = FVector(0, 0, 0);
    				//WorldSpaceVertexLocation.
    					//GetActorLocation() + GetTransform().TransformVector() 
    				VertexBuffer->VertexPosition(Index) = FVector(1100.0, -1100.0, 110);
    				UE_LOG(LogTemp, Warning, TEXT("My Location is: %s"), *VertexBuffer->VertexPosition(Index).ToString());
    				
    			}
    		}
    	}
    //StaticMeshComponent->GetStaticMesh()->PostEditChange();
    //	StaticMeshComponent->GetStaticMesh()->PostLoad();
    //	StaticMeshComponent = NULL;
    		return vertices;
    	
    }

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a740a38b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a740a38b](https://forums.unrealengine.com/u/anonymous_user_a740a38b)\
**Post date:** [October 26, 2020, 2:30am UTC](https://forums.unrealengine.com/t/how-modify-vertex-in-static-mesh-c/471175/2 "2020-10-26T02:30:31Z")

</div>

Hello, may I ask you a question? There are some errors in my code and I don’t know why.

 ![319461-question1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/4/784bea8ac2c842e7092180973e883d34e73ca0b6.png)

---

<div class="post-metadata">

**Author:** ![RedstoneExpert\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RedstoneExpert\_1](https://forums.unrealengine.com/u/RedstoneExpert_1)\
**Post date:** [June 7, 2021, 10:36am UTC](https://forums.unrealengine.com/t/how-modify-vertex-in-static-mesh-c/471175/3 "2021-06-07T10:36:18Z")

</div>

You are missing #include at the top of the file.

---

<div class="post-metadata">

**Author:** ![dandingol03](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dandingol03/32/769404_2.png) [@dandingol03](https://forums.unrealengine.com/u/dandingol03)\
**Post date:** [November 17, 2023, 10:47am UTC](https://forums.unrealengine.com/t/how-modify-vertex-in-static-mesh-c/471175/5 "2023-11-17T10:47:31Z")

</div>

You should call `rhilockbuffer` after all.
