This is how I set it up:
AMasterObject::AMasterObject()
...
static ConstructorHelpers::FObjectFinder<UMaterial> MAT(TEXT("Material'/Game/Materials/Basic/M_Color.M_Color'"));
if (MAT.Object != nullptr)
{
mat = MAT.Object;
}
...
void AMasterObject::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
TArray<UActorComponent*> temp = Mesh->GetOwner()->GetComponentsByTag(UActorComponent::StaticClass(), "MESH");
for (int32 i=0;i!=temp.Num();++i)
{
UMasterRootMesh* tempMesh = Cast<UMasterRootMesh>(temp[i]);
if (tempMesh != nullptr)
{
TArray<UMaterialInterface*> mats = tempMesh->GetMaterials();
for (int32 k=0;k!=mats.Num();++k)
{
UMaterialInstanceDynamic* mat_inst = UMaterialInstanceDynamic::Create(mat, tempMesh->GetOwner());
tempMesh->SetMaterial(k, mat_inst);
mat_inst->SetVectorParameterValue("Color", FLinearColor(FMath::FRandRange(0.0f, 1.0f), FMath::FRandRange(0.0f, 1.0f), FMath::FRandRange(0.0f, 1.0f)));
mat_inst->SetScalarParameterValue("Metallic", FMath::FRandRange(0.0f, 1.0f));
mat_inst->SetScalarParameterValue("Roughness", FMath::FRandRange(0.0f, 1.0f));
}
}
}
}
Outcome: random color/etc everytime I click “Compile” or move any of the meshes
But anyway this was solved so thanks, just curious about that