Hi I am using a scriptibleobject in unity that holds data for the store in my game it has been working fine for awhile now, but when I opened unity today after updating unity hub I got this error in my code
ArgumentException: JSON parse error: The document is empty. UnityEngine.JsonUtility.FromJsonOverwrite (System.String json, System.Object objectToOverwrite) (at <1386288601af43018501cce2912f52f4>:0)
it trowed the error anywhere I referenced the LoadDataFromFile function in my ScriptableObjec objects code.The error was on line 50 of my code. thank you for your time
here is the ScriptableObjects code
using System.Collections.Concurrent;
using System.ComponentModel.Design;
using UnityEngine;
using System.IO;
using System;
[CreateAssetMenu(fileName = "data",menuName = "sss",order = 1)]
public class sss : ScriptableObject
{
public float coins = 0f;
public float speed = 10f;
public float jump = 25f;
public bool buyspeed = false;
public bool buyjump = false;
public bool shotgununlock = false;
public bool set = true;
public int face = 1;
public int gun = 1;
public bool sniperunlock = false;
private const string FILENAME = "sss.dat";
public void SaveToFile()
{
var filePath = Path.Combine(Application.persistentDataPath, FILENAME);
if (!File.Exists(filePath))
{
File.Create(filePath);
}
var json = JsonUtility.ToJson(this);
File.WriteAllText(filePath, json);
}
public void LoadDataFromFile()
{
var filePath = Path.Combine(Application.persistentDataPath, FILENAME);
if (!File.Exists(filePath))
{
//Debug.LogWarning($"File /"{ filePath}/ " not found!, this);
return;
}
var json = File.ReadAllText(filePath);
JsonUtility.FromJsonOverwrite(json, this); //<-----this line of code
}
}