From 3796b0ccaef0aeb429313fdfb70b4cb147a03b3b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 13 Jan 2025 16:07:47 +0100 Subject: [PATCH] Revert #3117 and do it different way as some types can be valid even if different thus use internal parameter setter for type validation --- Source/Engine/Content/Assets/MaterialBase.cpp | 15 ++++----------- Source/Engine/Content/Assets/MaterialBase.h | 3 +-- .../Engine/Graphics/Materials/MaterialParams.cpp | 7 ++++++- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Source/Engine/Content/Assets/MaterialBase.cpp b/Source/Engine/Content/Assets/MaterialBase.cpp index 9751f86d4..9e980687a 100644 --- a/Source/Engine/Content/Assets/MaterialBase.cpp +++ b/Source/Engine/Content/Assets/MaterialBase.cpp @@ -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()); } } diff --git a/Source/Engine/Content/Assets/MaterialBase.h b/Source/Engine/Content/Assets/MaterialBase.h index 3d6487772..ec5681e27 100644 --- a/Source/Engine/Content/Assets/MaterialBase.h +++ b/Source/Engine/Content/Assets/MaterialBase.h @@ -66,8 +66,7 @@ public: /// The parameter name. /// The value to set. /// True to warn if parameter is missing, otherwise will do nothing. - /// True to warn if value is wrong type, otherwise will do nothing. - 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); /// /// Creates the virtual material instance of this material which allows to override any material parameters. diff --git a/Source/Engine/Graphics/Materials/MaterialParams.cpp b/Source/Engine/Graphics/Materials/MaterialParams.cpp index 30064222b..7329ef2ff 100644 --- a/Source/Engine/Graphics/Materials/MaterialParams.cpp +++ b/Source/Engine/Graphics/Materials/MaterialParams.cpp @@ -214,9 +214,11 @@ void MaterialParameter::SetValue(const Variant& value) break; case VariantType::Object: _asAsset = Cast(value.AsObject); + invalidType = _asAsset == nullptr && value.AsObject != nullptr; break; case VariantType::Asset: _asAsset = Cast(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(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(value.AsObject); + invalidType = _asAsset == nullptr && value.AsObject != nullptr; break; case VariantType::Asset: _asAsset = Cast(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)); } }