InvalidCastException: Specified cast is not valid in Behavior.SetVariableValue method

Noxalus

New member
It occurs when I try to set an object containing an integer in a shared variable that expects a float.

I fixed it updating the class SharedVariables.cs (line 151) from this:

C#:
mValue = (T)value;

To this:

C#:
mValue = (T)Convert.ChangeType(value, typeof(T));
 
After further tests, it seems that the "value" must implement IConvertible interface and the update trigger an "InvalidCastException" for some type (or when "value" is null), I updated the code like that:

Code:
if (value is IConvertible)
{
    mValue = (T)Convert.ChangeType(value, typeof(T));
}
else
{
    mValue = (T)value;
}
 
Top