Hi. I have a procedural Mesh component. All it is is a triangle. I would like to make the whole thing red.
So…
JtMesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedJtMesh"));
JtMesh->SetMobility(EComponentMobility::Movable);
// Make a triangle
TArray<FVector> vertices;
vertices.Add(FVector(0, 0, 0));
vertices.Add(FVector(0, 100, 0));
vertices.Add(FVector(0, 0, 100));
TArray<int32> Triangles;
Triangles.Add(0);
Triangles.Add(2);
Triangles.Add(1);
TArray<FVector> normals;
normals.Add(FVector(1, 0, 0));
normals.Add(FVector(1, 0, 0));
normals.Add(FVector(1, 0, 0));
TArray<FVector2D> UV0;
UV0.Add(FVector2D(0, 0));
UV0.Add(FVector2D(0, 10));
UV0.Add(FVector2D(10, 10));
TArray<FColor> vertexColors;
//vertexColors.Add(FColor(200, 0, 0, 1));
//vertexColors.Add(FColor(200, 0, 0, 1));
//vertexColors.Add(FColor(200, 0, 0, 1));
TArray<FProcMeshTangent> tangents;
tangents.Add(FProcMeshTangent(1, 1, 1));
tangents.Add(FProcMeshTangent(1, 1, 1));
tangents.Add(FProcMeshTangent(1, 1, 1));
// Make the mesh section
JtMesh->CreateMeshSection(0, vertices, Triangles, normals, UV0, vertexColors, tangents, false);
LeMaterial = UMaterial::GetDefaultMaterial(MD_Surface);
UMaterialInstanceDynamic * InstanceMaterial = UMaterialInstanceDynamic::Create(LeMaterial, NULL);
// Add a vector parameter for the color
InstanceMaterial->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(100.0f, 0.0f, 0.0f));
// Set the material
JtMesh->SetMaterial(numMeshSections, InstanceMaterial);
Upon doing this, I have a vector parameter for the color. I can see this in the designer…
But it does not change the color of the rendered object. How do I apply this parameter as the material of my mesh?