diff --git a/Source/Engine/Content/Assets/MaterialBase.cpp b/Source/Engine/Content/Assets/MaterialBase.cpp
index d537a5746..9751f86d4 100644
--- a/Source/Engine/Content/Assets/MaterialBase.cpp
+++ b/Source/Engine/Content/Assets/MaterialBase.cpp
@@ -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)
{
diff --git a/Source/Engine/Content/Assets/MaterialBase.h b/Source/Engine/Content/Assets/MaterialBase.h
index 81316b106..3d6487772 100644
--- a/Source/Engine/Content/Assets/MaterialBase.h
+++ b/Source/Engine/Content/Assets/MaterialBase.h
@@ -65,8 +65,9 @@ public:
///
/// The parameter name.
/// The value to set.
- /// True if warn if parameter is missing, otherwise will do nothing.
- API_FUNCTION() void SetParameterValue(const StringView& name, const Variant& value, bool warnIfMissing = true);
+ /// 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);
///
/// Creates the virtual material instance of this material which allows to override any material parameters.