How to get character currency in another scene?

EVG

Member
Sorry for this question, maybe I don’t understand the principle of working with currency at all, but how can I get the character’s currency regardless of the scene?
For example:
There is a character in the "Game" scene, during the game he receives and accumulates currency. How can I now use this accumulated currency in another "Menu" scene? For example, to buy weapons or something else.
I have tried saving and loading values with your code:
C#:
    public object RecordData()
    {
        SaveSystemManager.Save(saveSlot, false);
        var saveDataInfo = SaveSystemManager.GetCurrentSaveDataInfo();
        var saveData = saveDataInfo.Data;
        return saveData;
    }
    public void ApplyData(object data)
    {
        if (data == null) return;
        var saveData = data as SaveData;
        SaveSystemManager.Load(saveSlot, saveData);
    }
Everything works well for the current scene. But how can I get the currency in another scene from the same owner, but without him?
 
The Save system works by saving and loading objects registered to the save system with a unique Key.
So if that code above does not work for you, that means the save key for your Currency is different between the two scenes.

Usually the "Saver" component has a field to set the key, although by default it uses the name of the gameobject it is on.
You can debug the save data by printing a JSON version of the save so that you can read it and check what's wrong.

If you do not want to use the Save system and instead just copy the currency, you can.
 
Top