Hi,
so i’m trying to create a “PlayerStats” object using the JsonUtility class. There are no errors in the Editor but whenever i run the code i get the Exception : System.ArgumentException: Cannot deserialize JSON to new instances of type ‘PlayerStats.’ and i don’t know why. I use the method just like they do in the documentation but i keep getting that exception. The json file was created using JU.ToJson and should work without problem. What am i missing ?
if (File.Exists(savePath + "\\" + name + ".json")) {
string saveData = File.ReadAllText(savePath + "\\" + name + ".json");
GameObject localPlayer = (GameObject)Instantiate(Resources.Load("Player/" + JsonUtility.FromJson<PlayerStats>(saveData).race.ToString()));
}
the json file :
{
"race": 0,
"playerName": "xxx",
"initative": 10.0
}
PlayerStats.cs :
public class PlayerStats : MonoBehaviour {
public Race race;
public string playerName;
public float initative = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}