how to get the parameters of a material like roughness, etc

hello,
i’ve been searching through the documentation but i still cant figure out how to use the function UMaterial::GetParameterValue(). I dont understand its parameters quite well and ive tested different things, for instance :
FMaterialParameterMetadata OutParameterMeta;
HitMaterialInterface->GetParameterValue(EMaterialParameterType::Scalar, FMaterialParameterInfo(FName(“Roughness”)), OutParameterMeta);
UE_LOG(LogTemp, Warning, TEXT(“roughness %f” ),OutParameterMeta.Value.AsScalar());

My goal is to cast a ray to an object and getting its material in order to get the parameters of this material like its base color, metallic, roughness
i’ve tried using GetScalarParameterValue() before too but it didnt work for me either (i constantly get 0 as values even though its a material i created myself and defined its roughness to something different to 0)

So if anyone could tell me some direction on how to use those functions or anything else, even another way to get what i want, that would be of great help. Even small information would be nice, im quite desesperate here.

What does your material look like?

i just set its base color, metallic and roughness parameters

Ok, so I believe there’s some confusion going on here. A material parameter value is not the value of the individual material attributes like “Roughness”, “Tangent”, “Normal”, etc. It’s the value of a user defined parameter. Your issue is the fact that you don’t actually have a parameter for your “Roughness” at all…you have a constant value plugged in. You need to create a scalar parameter (hold s key and click in the graph). Name the parameter whatever you want. The name you choose will be the name you put in the call to GetParameterValue. Keep in mind that if you wish to set the parameter programmatically in the future you’ll need to create a dynamic material instance.

1 Like

ok! thank you now i understand what i did wrong :slight_smile: