Hello I’ve been trying to use JsonUtility.ToJson() to save data in my game, but the Utility just creates a pair of {} brackets in the file. I’ve put it in debug.log and it just prints the brackets to the console. This is very odd as the class containing my save data has several different ints and a list in it. I’ve looked at multiple tutorials and they all say to do it like this. Am I missing something?
[Serializable]public class SaveData
{
public List<EntityLocations> entityLocations = new List<EntityLocations>();
internal int health, healthMax, mana, manaMax, stam, stamMax;
}
The EntityLocations type must also be marked serializable.
Also, the internal fields should be marked with [SerializeField] if they’re meant to be serialized, since they’re not public.
To add to the above, you need to follow all of Unity’s normal serialization rules when dealing with JsonUtility, as it pretty much is just Unity’s normal serialization protocol.