Merge branch 'Tryibion-mat-warn-wrong-type'

This commit is contained in:
Wojtek Figat
2025-01-06 23:58:04 +01:00
2 changed files with 13 additions and 5 deletions

View File

@@ -25,13 +25,20 @@ Variant MaterialBase::GetParameterValue(const StringView& name)
return Variant::Null;
}
void MaterialBase::SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing)
void MaterialBase::SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing, bool warnIfWrongType)
{
const auto param = Params.Get(name);
if (param)
{
param->SetValue(value);
param->SetIsOverride(true);
if (Variant::CanCast(value, param->GetValue().Type))
{
param->SetValue(value);
param->SetIsOverride(true);
}
else if (warnIfWrongType)
{
LOG(Warning, "Material parameter '{0}' in material {1} is type '{2}' and not type '{3}'.", String(name), ToString(), param->GetValue().Type, value.Type);
}
}
else if (warnIfMissing)
{

View File

@@ -65,8 +65,9 @@ public:
/// </summary>
/// <param name="name">The parameter name.</param>
/// <param name="value">The value to set.</param>
/// <param name="warnIfMissing">True if warn if parameter is missing, otherwise will do nothing.</param>
API_FUNCTION() void SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing = true);
/// <param name="warnIfMissing">True to warn if parameter is missing, otherwise will do nothing.</param>
/// <param name="warnIfWrongType">True to warn if value is wrong type, otherwise will do nothing.</param>
API_FUNCTION() void SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing = true, bool warnIfWrongType = true);
/// <summary>
/// Creates the virtual material instance of this material which allows to override any material parameters.