I try to save game data in PlayerPrefs as JSON string. I read in documentation that I can use plain struct/class with [Serializable] attribute but it doesn't work...
First I thought that data didn't arrive so I start to debug and watch values and saw that data is arrived. Then thought that (may be) SetString method is asynchronous, but when I evaluate the expression JsonUtility.ToJson(GameData) it showed me empty string again
Also I tried:
- add
[SerializeField]to both fields - use
intinstead ofenum - add/remove
[Serializable]attribute for enum

The problems disappears when I don't use Nullable fields. Is there any workaround to use Nullable fields?
using System;
using UnityEngine;
[Serializable]
public enum FPSValues {
High = 60,
Low = 30
}
[Serializable]
public struct GameData {
public FPSValues? FPS;
public bool? IsAudioEnabled;
}
public class GameDataManager : MonoBehaviour {
public static GameData GameData;
private void Awake() {
Load();
}
public static void Save() {
PlayerPrefs.SetString("GameData", JsonUtility.ToJson(GameData));
var x = PlayerPrefs.GetString("GameData");
}
private void Load() {
var x = JsonUtility.FromJson<GameData>(PlayerPrefs.GetString("GameData"));
GameData = x;
}
}
```