komilll
(komilll)
January 6, 2018, 8:35pm
1
Hello, I am trying to change material color of standard UE4 Mannequin skeletal mesh but there is nothing hapenning both in viewport and in game.
AEnemyBase::AEnemyBase()
{
mesh_ = GetMesh();
mesh_->SetupAttachment(GetCapsuleComponent());
TArray<class UMaterialInterface*> materials = GetMesh()->GetMaterials();
for (int i = 0; i < materials.Num(); i++)
{
UMaterialInstanceDynamic* matInstance_ = UMaterialInstanceDynamic::Create(materials[i], this);
matInstance_->SetVectorParameterValue(FName(TEXT("_BodyColor")), characterColor);
GetMesh()->SetMaterial(i, matInstance_);
}
}
xlar8or
(xlar8or)
January 6, 2018, 8:46pm
2
Hey there, first of all you dont need the FName(TEXT, just do “_BodyColor”, what you are doing there is kind of the same as doing 3 + 1 - 1, instead of using just 3. Second, i would create the dynamic material in the begin play and using this command:
UMaterialInterface * Material = GetMesh()->GetMaterial(i);
UMaterialInstanceDynamic* matInstance = GetMesh()->CreateDynamicMaterialInstance(i, Material);
if(matInstance != nullptr)
matInstance->SetVectorParameterValue("_BodyColor", characterColor);
See if that works.
xlar8or
(xlar8or)
January 8, 2018, 9:01am
4
Hey good to know, the inner code of unreal probably has some verification that prevents it from running on the contructor.