Revert #3117 and do it different way as some types can be valid even if different thus use internal parameter setter for type validation
This commit is contained in:
@@ -25,24 +25,17 @@ Variant MaterialBase::GetParameterValue(const StringView& name)
|
||||
return Variant::Null;
|
||||
}
|
||||
|
||||
void MaterialBase::SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing, bool warnIfWrongType)
|
||||
void MaterialBase::SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing)
|
||||
{
|
||||
const auto param = Params.Get(name);
|
||||
if (param)
|
||||
{
|
||||
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);
|
||||
}
|
||||
param->SetValue(value);
|
||||
param->SetIsOverride(true);
|
||||
}
|
||||
else if (warnIfMissing)
|
||||
{
|
||||
LOG(Warning, "Missing material parameter '{0}' in material {1}", String(name), ToString());
|
||||
LOG(Warning, "Missing material parameter '{0}' in material {1}", name, ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ public:
|
||||
/// <param name="name">The parameter name.</param>
|
||||
/// <param name="value">The value to set.</param>
|
||||
/// <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);
|
||||
API_FUNCTION() void SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing = true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the virtual material instance of this material which allows to override any material parameters.
|
||||
|
||||
@@ -214,9 +214,11 @@ void MaterialParameter::SetValue(const Variant& value)
|
||||
break;
|
||||
case VariantType::Object:
|
||||
_asAsset = Cast<TextureBase>(value.AsObject);
|
||||
invalidType = _asAsset == nullptr && value.AsObject != nullptr;
|
||||
break;
|
||||
case VariantType::Asset:
|
||||
_asAsset = Cast<TextureBase>(value.AsAsset);
|
||||
invalidType = _asAsset == nullptr && value.AsAsset != nullptr;
|
||||
break;
|
||||
default:
|
||||
invalidType = true;
|
||||
@@ -239,6 +241,7 @@ void MaterialParameter::SetValue(const Variant& value)
|
||||
break;
|
||||
case VariantType::Object:
|
||||
_asGPUTexture = Cast<GPUTexture>(value.AsObject);
|
||||
invalidType = _asGPUTexture == nullptr && value.AsObject != nullptr;
|
||||
break;
|
||||
default:
|
||||
invalidType = true;
|
||||
@@ -258,9 +261,11 @@ void MaterialParameter::SetValue(const Variant& value)
|
||||
break;
|
||||
case VariantType::Object:
|
||||
_asAsset = Cast<GameplayGlobals>(value.AsObject);
|
||||
invalidType = _asAsset == nullptr && value.AsObject != nullptr;
|
||||
break;
|
||||
case VariantType::Asset:
|
||||
_asAsset = Cast<GameplayGlobals>(value.AsAsset);
|
||||
invalidType = _asAsset == nullptr && value.AsAsset != nullptr;
|
||||
break;
|
||||
default:
|
||||
invalidType = true;
|
||||
@@ -273,7 +278,7 @@ void MaterialParameter::SetValue(const Variant& value)
|
||||
}
|
||||
if (invalidType)
|
||||
{
|
||||
LOG(Error, "Invalid material parameter value type {0} to set (param type: {1})", value.Type, ScriptingEnum::ToString(_type));
|
||||
LOG(Error, "Invalid material parameter value '{}' of type '{}' to set (expected type: {})", value.ToString(), value.Type, ScriptingEnum::ToString(_type));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user