Search Unity

Feedback Difficulty on Cloud Save + Economy

Discussion in 'Cloud Save' started by xgarciadevs, Feb 24, 2023.

  1. xgarciadevs

    xgarciadevs

    Joined:
    Feb 23, 2020
    Posts:
    2
    Hey so this is probably seen a lot.. a LOT. I am new to using Unity Cloud Save and I am trying to use it on a game I am working on, I was pairing it with the Economy part of Unity also but I am having difficulty figuring out how I can save the player data to the cloud so it is there when the game is reopened or updated. I've looked through the tutorials and other work people have done but I am still having issues on remaking it to work for me. Does anybody have tips I could use to get this working for me?
     
  2. Unity_AndyP

    Unity_AndyP

    Unity Technologies

    Joined:
    Jun 23, 2021
    Posts:
    63
    You can save the items to the ForceSaveAsync method, this sends up a dictionary of key-value pairs to the service. The "key" would be whatever parameter you want this to be, health, location, level, active quest, and the value would be the correct state at that time. This could be saved at any point of your choosing such as at the end of a level, once a building has been completed ect.

    As an example:

    public async void SaveSomeData()
    {
    var data = new Dictionary<string, object>{{"key", "someValue"}};
    await CloudSaveService.Instance.Data.ForceSaveAsync(data);
    }

    At whatever point you want to load in the data, in your example when the game boots up you can simply load the data using the LoadAsync method. This will pull the player's data down from the service (from whatever point it was last saved) and you can extract it, assigning each "key" to the associated parameter.

    As an example:

    public async void LoadSomeData()
    {
    Dictionary<string, string> savedData = await CloudSaveService.Instance.Data.LoadAsync(new HashSet<string>{"key"});
    Debug.Log("Done: " + savedData["key"]);
    }


    We will know it's the correct player's data as we will use the AuthenticationID to match it up.

    You can find more information on how to do this form here
     
    xgarciadevs likes this.
  3. xgarciadevs

    xgarciadevs

    Joined:
    Feb 23, 2020
    Posts:
    2
    That is really helpful, thank you so much!
     
  4. TheKingNuro

    TheKingNuro

    Joined:
    Nov 13, 2021
    Posts:
    5
    Can I ask a question if possible?

    If I try to loadsomedata how do I get an int back? Do I have to parse it to int? What would a correct way be to retrieve bunch of data?

    Lets say I want to retrieve 10 keys all with their values from strings to ints how does that work? I'm new to cloud save and dictionaries frankly. I can't seem to figure out how to retrieve data correctly.

    Currently I have something like this -

    var data = new Dictionary<string, object>();
    data.Add("Gold", ES3.Load<int>("Gold", 10));
    data.Add("ClickDamage", ES3.Load<int>("ClickDamage", 10));

    await CloudSaveService.Instance.Data.ForceSaveAsync(data);

    and

    Dictionary<string, string> savedData = await CloudSaveService.Instance.Data.LoadAsync(new HashSet<string>{"Gold"});

    gold = savedData["Gold"]; <- error cause string
    Debug.Log("Done: " + savedData["Gold"]);

    but at the last part I want to retrieve multiple keys do I have to get the list of keys for this? THe save and load works I'm just kinda stuck with which type of data and how many I can retrieve.
     
  5. one-up

    one-up

    Joined:
    Mar 22, 2018
    Posts:
    5

    Same question. Any update?