My settings.json (generated with JsonUtility.ToJson):

    "masterVolume": 0.10000000149011612,
    "fullScreenMode": 1,
    "cheatsEnabled": false

Offending line:

SettingsData sd = JsonUtility.FromJson<SettingsData>(Application.dataPath + "/Settings/settings.json");

My SettingsData-class.

public class SettingsData
    [SerializeField]public float masterVolume;
    [SerializeField]public int fullScreenMode;
    [SerializeField]public bool cheatsEnabled;

    public SettingsData(float masterVolume, FullScreenMode fullScreenMode, bool cheatsEnabled)
        this.masterVolume = masterVolume;
        this.fullScreenMode = (int)fullScreenMode;
        this.cheatsEnabled = cheatsEnabled;

I really can't fathom why it's having trouble reading this back in, I even tried to save the enum as an int instead, but still no luck.


I tried to read the filepath as the actual json file, here's the solution:

string json = File.ReadAllText(Application.dataPath + "/Settings/settings.json");
SettingsData sd = JsonUtility.FromJson<SettingsData>(json);
  • 2
    \$\begingroup\$ Heh. I guess you should not used the word that was edited out :) \$\endgroup\$ – Vaillancourt Jul 17 '18 at 19:56
  • \$\begingroup\$ @AlexandreVaillancourt Yeah, I was in a slight mood when making this post. \$\endgroup\$ – ag4w Jul 18 '18 at 16:32
  • \$\begingroup\$ Still, thanks for coming back and posting the answer. If you could mark it as accepted when the system lets you do it, it would be great! \$\endgroup\$ – Vaillancourt Jul 18 '18 at 16:48
  • 1
    \$\begingroup\$ Yeah, there's a two days delay, so I'll do it tomorrow. \$\endgroup\$ – ag4w Jul 18 '18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.