Improve #3138 to pass over setting value to null and via proper cast so value type stays the same
This commit is contained in:
@@ -3439,6 +3439,16 @@ bool Variant::CanCast(const Variant& v, const VariantType& to)
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case VariantType::Null:
|
||||
switch (to.Type)
|
||||
{
|
||||
case VariantType::Asset:
|
||||
case VariantType::ManagedObject:
|
||||
case VariantType::Object:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -3912,6 +3922,23 @@ Variant Variant::Cast(const Variant& v, const VariantType& to)
|
||||
default: ;
|
||||
}
|
||||
break;
|
||||
case VariantType::Null:
|
||||
switch (to.Type)
|
||||
{
|
||||
case VariantType::Asset:
|
||||
return Variant((Asset*)nullptr);
|
||||
case VariantType::Object:
|
||||
return Variant((ScriptingObject*)nullptr);
|
||||
case VariantType::ManagedObject:
|
||||
{
|
||||
Variant result;
|
||||
result.SetType(VariantType(VariantType::ManagedObject));
|
||||
result.MANAGED_GC_HANDLE = 0;
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
LOG(Error, "Cannot cast Variant from {0} to {1}", v.Type, to);
|
||||
|
||||
@@ -292,11 +292,12 @@ void AnimatedModel::SetParameterValue(const StringView& name, const Variant& val
|
||||
{
|
||||
if (param.Name == name)
|
||||
{
|
||||
if (Variant::CanCast(value, param.Value.Type))
|
||||
if (param.Value.Type == value.Type)
|
||||
param.Value = value;
|
||||
else if (Variant::CanCast(value, param.Value.Type))
|
||||
param.Value = Variant::Cast(value, param.Value.Type);
|
||||
else
|
||||
LOG(Warning, "Animation Graph parameter '{0}' in AnimatedModel {1} is type '{2}' and not type '{3}'.", String(name), ToString(), param.Value.Type, value.Type);
|
||||
|
||||
LOG(Warning, "Animation Graph parameter '{0}' in AnimatedModel {1} is type '{2}' and not type '{3}'.", name, ToString(), param.Value.Type, value.Type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user