I created a Unreal project using C++ Vehicle template. I would like to change the color of the Vehicle on Begin Play. The specific material that I would like to change it’s color is the third material (element 2).
This is what I have inside BeginPlay function but it does not work.
UMaterialInstanceDynamic* myMaterial = UMaterialInstanceDynamic::Create(GetMesh()->GetMaterial(2), NULL);
if (myMaterial)
{
myMaterial->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(0.0f, 0.0f, 0.0f));
GetMesh()->SetMaterial(2, myMaterial);
}
Kindly help.