Hello,
I’m using reflection to save my script variable values to a file (Save game), using UnityScript.
Everything is working as it should except for boolean variables.
I can write a script to a file, open the file and use Script.GetType()þGetField(varName).SetValue(Script, value) to load the data from the file into the script again. This works for all variables except for boolean.
SetValue() isn’t working. No boolean value is updated. No errors are being thrown.
A small snippet of my code : Its saving all the values into a string.
for(var val2 :String in Arr)
{
name = val2.Substring(0,val2.IndexOf(":"));
var Valu =val2.Substring(val2.IndexOf(":")+1);
var Valu2;
var count : int = 0;
var FI= P.GetField(name);
var val = FI.GetValue(Script);
try
{
var Type11 : String= val.GetType().Name;
Type11.Trim();
switch(Type11)
{
case "Int32":
Valu2 = int.Parse(Valu);
FI.SetValue(Script,Valu2 );
break;
case "Boolean":
print(FI.Name + " : "+ val.ToString());
var bol : boolean = false;
if(val.ToString() == "False")
{
bol = false;
FI.SetValue(Script,bol);
print("Setting "+ FI + ": false ");
}
else
{
bol = true;
FI.SetValue(Script,bol);
}
}
}
Any Idea what might cause this?