Hello All,
I wonder is there a way to edit world terrain tileset material at runtime ? I follow the Material Editing tutorial ,it works fine. But i want to change the color parameter in my custom material layer at runtime, it doesn’t work.
For this goal,it’s a two-step process:
- Get the UMaterialInstanceDynamic of tileset material,i did it by this:
void ASMainActor::onTileLoaded()
{
TArray<UStaticMeshComponent*>aa;
BTerrain->GetComponents(aa);
if (aa.Num() > 0) {
int kcount = aa.Num();
for (auto& item : aa)
{
UMaterialInstanceDynamic* pMaterial =
Cast<UMaterialInstanceDynamic>(item->GetMaterial(0));
SetColor(pMaterial);
}
}
}
*BTerrain is the world terrain tileset
SetColor is one function that change the material layer parameter
- Set the vectorparameter of BlendParameter,like that:
void ASMainActor::SetColor(UMaterialInstanceDynamic* _pIndynamic)
{
UMaterialFunctionMaterialLayerBlend* pMF = LoadObject<UMaterialFunctionMaterialLayerBlend>(NULL, TEXT("MaterialFunctionMaterialLayerBlend'/Game/Materials/MLB_AreaTint.MLB_AreaTint'"));
FMaterialParameterInfo xxy = _pIndynamic->GetParameterInfo(EMaterialParameterAssociation::BlendParameter, FName("BColor"), pMF);
FMaterialParameterInfo mmy(xxy.Name, xxy.Association, xxy.Index);
_pIndynamic->SetVectorParameterValueByInfo(mmy, FLinearColor::Blue);
}
It didn’t work.What should I do?
Thanks in Advance.