Loading a custom class doesn't work?
Posted: Mon Jul 11, 2022 7:51 pm
Hello I tried saving a custom class for my character that contains string:Name, Dictionary<string,float> floats, Dictionary<string,bool> bools, Dictionary<string,string> strings data types.
Then I tried to test saving the values using:
Saving didn't produce errors, but when I tried to Load like this:
loadedChar returns null. Any way to do this correctly?
Code: Select all
public class Character : MonoBehaviour
{
public string characterName = new string("default");
public Dictionary<string, float> floatAttributes = new Dictionary<string, float>();
public Dictionary<string, bool> boolAttributes = new Dictionary<string, bool>();
public Dictionary<string, string> stringAttributes = new Dictionary<string, string>();
public void Initialize(string name, Dictionary<string, float> floats, Dictionary<string,bool> bools, Dictionary<string,string> strings)
{
characterName = name;
floatAttributes = floats;
boolAttributes = bools;
stringAttributes = strings;
}
}
Code: Select all
Character newChar = new Character();
newChar.characterName = "Boi";
newChar.floatAttributes.Add("strength", 15);
newChar.floatAttributes.Add("intelligence", 10);
newChar.boolAttributes.Add("isHuman", true);
newChar.stringAttributes.Add("Catch Phrase", "Deez Nutz");
ES3.Save(newChar.characterName, newChar);
Code: Select all
Character loadedChar = ES3.Load("Boi", new Character());