How can I assign a material to all LODs?

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.

43889-shirtlods.jpg

Any help is appreciated.

It seems this guy had the same question and got it resolved. Check it out. It’s blueprint but you can easily trnsfer the logic to C++

Thanks maparizeau! Your answer pushed me to the right direction.

In line 23 I checked for the Number of elements on the StaticMeshComponent:

CompMats = EnvironmentMeshComponent->GetMaterials();

I logged it, and it did spit out “1”. That obvioiusly couldn’t be right, since I have multiple LODs. Instead I should have checked for the Number of material elements on the Mesh of the StaticMeshComponent:

CompMats = EnvironmentMeshComponent->StaticMesh->Materials;

Now it seems to work perfectly. Thanks again!

my pleasure and happy game deving :wink: