Unity Static Singleton JSON Serialisation I have a static PlayerData singleton which stores all the data for the player (gold, upgrades, heroes etc) but JsonUtility cannot serialise static or private methods so I have implemented a singleton with an intermediate SaveFile struct which is used in the serialisation.
PlayerData will have more complex objects likes HeroCollection etc but for now, I simply have a gold stat.
I am looking for a potentially better alternative solution or simply how to improve this.
Thanks.
struct SaveFile
{
    public int Gold;
}

public class PlayerData
{
    static PlayerData Instance = null;

    // # - Private Attributes - #
    int _Gold;

    // ... Heroes
    // ... Upgrades
    // ... Etc
    // # - - - - - - - #



    // # - Public Static Attributes - #
    public static int Gold { get { return Instance._Gold; } set { Instance._Gold = value; } }
    // # - - - - - - - #

    public static void Create(string json)
    {
        if (Instance == null)
            Instance = FromJson(json);
    }

    public static string ToJson()
    {
        return JsonUtility.ToJson(

            new SaveFile()
            {
                Gold = Instance._Gold
            }

        );
    }

    static PlayerData FromJson(string json)
    {
        SaveFile save = JsonUtility.FromJson&lt;SaveFile&gt;(json);

        return new PlayerData()
        {
            _Gold = save.Gold
        };
    }
}
Here are my observations after a quick review:

First of all your class is not a thread-safe singleton.

Please read Jon Skeet's guidance how to implement is properly.


As I understand you would like to implement a Memento pattern in C#.

There are a couple of good samples how to implement it properly: 1, 2, 3
BTW you can also use the Solid nuget package as well


Sorry but your naming is terrible, please try to follow some guideline, like:

Name your functions / methods in a way that they start with a verb, for example: SaveState, RestoreState
Name Your classes/ structs in a way that they are nouns (w/o adjective), for example: PlayerState,PortablePlayerState