Fix for road materials assignment from plugin quality preferences to static meshes using slotnames.

This commit is contained in:
CVC\jbelon 2018-03-02 10:23:46 +01:00
parent 01d0f1c570
commit 918f0c4e17
1 changed files with 20 additions and 11 deletions

View File

@ -412,17 +412,26 @@ void UCarlaSettings::SetAllRoadsLowQuality(UWorld* world) const
TArray<UActorComponent*> components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass());
for(int32 j=0; j<components.Num(); j++)
{
UStaticMeshComponent* staticmesh = Cast<UStaticMeshComponent>(components[j]);
if(staticmesh)
{
for(int32 k=0; k<staticmesh->GetNumMaterials(); k++)
{
if(LowRoadMaterials.IsValidIndex(k) && LowRoadMaterials[k].MaterialInterface && LowRoadMaterials[k].MaterialInterface->IsValidLowLevel())
{
staticmesh->SetMaterial(k, LowRoadMaterials[k].MaterialInterface);
}
}
}
UStaticMeshComponent* staticmesh = Cast<UStaticMeshComponent>(components[j]);
if(staticmesh)
{
TArray<FName> slotsnames = staticmesh->GetMaterialSlotNames();
for(int32 k=0; k<slotsnames.Num(); k++)
{
const FName &slotname = slotsnames[k];
bool found = LowRoadMaterials.ContainsByPredicate([staticmesh,slotname](const FStaticMaterial& material)
{
if(material.MaterialSlotName.IsEqual(slotname))
{
staticmesh->SetMaterial(
staticmesh->GetMaterialIndex(slotname),
material.MaterialInterface
);
return true;
} else return false;
});
}
}
}
}
}