1
\$\begingroup\$

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.

[System.Serializable]
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.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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);
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .