# DynamicMesh::SetVertexColor has no effect

**URL:** <https://forums.unrealengine.com/t/dynamicmesh-setvertexcolor-has-no-effect/2626000>\
**Category:** Programming & Scripting\
**Tags:** vertex-paint, unreal-engine, dynamic, CPP, question\
**Created:** [August 1, 2025, 6:19am UTC](https://forums.unrealengine.com/t/dynamicmesh-setvertexcolor-has-no-effect/2626000 "2025-08-01T06:19:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluKettle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/blukettle/32/872244_2.png) [@bluKettle](https://forums.unrealengine.com/u/bluKettle)\
**Post date:** [August 1, 2025, 6:19am UTC](https://forums.unrealengine.com/t/dynamicmesh-setvertexcolor-has-no-effect/2626000/1 "2025-08-01T06:19:14Z")

</div>

Hi people 🙂

im trying to update the vertex colors of a DynamicMesh but even if SetVertex works well, trying to use SetVertexColor in the same loop does absolutely nothing.

This is basically the code im using:

```auto
FDynamicMesh3 tempMesh = MeshComp->GetDynamicMesh()->GetMeshRef();

if (!tempMesh.HasVertexColors())
{
	tempMesh.EnableVertexColors(FVector3f(0.0f, 0.0f, 0.0f));
	tempMesh.EnableAttributes();
	tempMesh.Attributes()->EnablePrimaryColors();
}

for (int32 i : tempMesh.VertexIndicesItr())
{
	tempMesh.SetVertex(i, vertPos + ...);

	tempMesh.SetVertexColor(i, FVector3f(1.0f, 0.0f, 0.0f));
}

MeshComp->SetMesh(MoveTemp(tempMesh));
MeshComp->NotifyMeshUpdated();
MeshComp->UpdateCollision();

```

I also used a Material with vertex colors as the base color for debugging.  
Trying to ask ChatGPT only gave me hallucinated pseudo-code and i didn’t find any other solution online.

Thx for your help in advance!

---

<div class="post-metadata">

**Author:** ![Dasay2605](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dasay2605](https://forums.unrealengine.com/u/Dasay2605)\
**Post date:** [August 1, 2025, 4:42pm UTC](https://forums.unrealengine.com/t/dynamicmesh-setvertexcolor-has-no-effect/2626000/2 "2025-08-01T16:42:38Z")

</div>

You need to use `primatyColor` instead of `VertexColor`, so you should write something like this:

```cpp
FDynamicMesh3 tempMesh = MeshComp->GetDynamicMesh()->GetMeshRef();

if (!tempMesh.HasAttributes())
{
	tempMesh.EnableAttributes();
}
if (!tempMesh.Attributes()->HasPrimaryColors())
{
	tempMesh.Attributes()->EnablePrimaryColors();
}

FDynamicMeshColorOverlay* Colors = tempMesh.Attributes()->PrimaryColors();
Colors->ClearElements();
		
TArray<int32> ElemIDs;
ElemIDs.SetNum(tempMesh.MaxVertexID());
		
for (int32 i : tempMesh.VertexIndicesItr())
{
	tempMesh.SetVertex(i, vertPos + ...);
			
	ElemIDs[i] = Colors->AppendElement(FVector4f(1.0f, 0.0f, 0.0f, 0.0f));
}
for (int32 TriangleID : tempMesh.TriangleIndicesItr())
{
	FIndex3i Triangle = tempMesh.GetTriangle(TriangleID);
	Colors->SetTriangle(TriangleID, FIndex3i(ElemIDs[Triangle.A], ElemIDs[Triangle.B], ElemIDs[Triangle.C]) );
}

MeshComp->SetMesh(MoveTemp(tempMesh));
MeshComp->NotifyMeshUpdated();
MeshComp->UpdateCollision();

```

Also note: It is better to use a special function to get `FDynamicMesh3`. Using `GetMeshRef` is not recommended, use `EditMesh` instead, as shown below:

```cpp
MeshComp->GetDynamicMesh()->EditMesh([&](FDynamicMesh3& EditMesh)
{
	if (!EditMesh.HasAttributes())
	{
		EditMesh.EnableAttributes();
	}
	if (!EditMesh.Attributes()->HasPrimaryColors())
	{
		EditMesh.Attributes()->EnablePrimaryColors();
	}

	FDynamicMeshColorOverlay* Colors = EditMesh.Attributes()->PrimaryColors();
	Colors->ClearElements();
	TArray<int32> ElemIDs;
	ElemIDs.SetNum(EditMesh.MaxVertexID());
		
	for (int32 i : EditMesh.VertexIndicesItr())
	{
		tempMesh.SetVertex(i, vertPos + ...);
			
		ElemIDs[i] = Colors->AppendElement(FVector4f(1.0f, 0.0f, 0.0f, 0.0f));
	}
	for (int32 TriangleID : EditMesh.TriangleIndicesItr())
	{
		FIndex3i Triangle = EditMesh.GetTriangle(TriangleID);
		Colors->SetTriangle(TriangleID, FIndex3i(ElemIDs[Triangle.A], ElemIDs[Triangle.B], ElemIDs[Triangle.C]) );
	}
}, EDynamicMeshChangeType::GeneralEdit);

```

Both codes should give the same result.
