I have a c++ class that contains both static mesh and skeletal mesh, as components. And I have blueprint instances deriving from this class. These blueprint instances could be either static mesh or skeletal mesh
My question is I am updating the material by writing same code for both static mesh and skeletal mesh which i think duplication, an object could be either static mesh or skeletal mesh when its spawned
Is there a way we can better handle it by making use of coding templates or some other way to avoid writing the same code twice
for (UStaticMeshComponent* sm : StaticMeshComponents)
{
if (UMaterialInterface* DefaultMaterial = sm->GetMaterial(IndexOfMaterialToMakeDynamic))
{
DynamicMaterialInstance = UMaterialInstanceDynamic::Create(DefaultMaterial, this);
sm->SetMaterial(IMaterialDynamic, DynamicMaterialInstance);
}
}
for (USkeletalMeshComponent* sm : SkeletalMeshComponents)
{
if (UMaterialInterface* DefaultMaterial = sm->GetMaterial(IndexOfMaterialToMakeDynamic))
{
DynamicMaterialInstance = UMaterialInstanceDynamic::Create(DefaultMaterial, this);
sm->SetMaterial(MaterialDynamic, DynamicMaterialInstance);
}
}