Hello,
I wrote the following function for the constructor of my StaticMesh class to assign a material instance (of the already assigned material) to the model which can be tinted with any color:
void ASomPickup::UpdateMaterials()
{
//Get Original Material
if (Pickup_Material_Origin == NULL && !EnvironmentMesh->GetMaterial(0)->IsA(UMaterialInstanceDynamic::StaticClass()))
Pickup_Material_Origin = EnvironmentMesh->GetMaterial(0);
//Get and assign Material Instance
if (Pickup_Material_Origin != NULL)
{
if (Pickup_Material == NULL)
{
Pickup_Material = UMaterialInstanceDynamic::Create(Pickup_Material_Origin, this);
Pickup_Material->SetVectorParameterValue(FName(TEXT("Tint")), ColorTint);
}
TArray<UMaterialInterface*> CompMats;
if (EnvironmentMeshComponent != NULL)
{
CompMats = EnvironmentMeshComponent->GetMaterials();
for (int32 iMats = 0; iMats < CompMats.Num(); iMats++)
{
EnvironmentMeshComponent->SetMaterial(iMats, Pickup_Material);
}
}
}
}
Now the problem is that the tint only seems to have effect on the highest/“nearest” LOD of the model (LOD 0). It seems that the lower LODs don’t have the new instanced material assigned to them.
Any help is appreciated.