Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Saving a fake playerid and reading it back

Discussion in 'Cloud Save' started by jackward84, Jun 25, 2023.

  1. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Hello,

    I am asking a question about server authoritive data storage when I ask this question.

    It is possible to save a cloud save document with an entirely fake player id.

    Code (CSharp):
    1. bearer_token = get_access_token()
    2. player_id = "abcd"
    3. url = f"https://cloud-save.services.api.unity.com/v1/data/projects/{PROJECT_ID}/players/{player_id}/item-batch"
    4. header = {"Authorization": f"Bearer {bearer_token}"}
    5. r = requests.post(url, json={"data": [
    6.     {
    7.         "key": "Kills",
    8.         "value": 111
    9.     },    {
    10.         "key": "Deaths",
    11.         "value": 111
    12.     }
    13. ]}, headers=header)
    This generates no error, and there is in fact a player saved with the player id
    abcd
    .

    Reading it back, there is also no issue:

    Code (CSharp):
    1. get = f"https://cloud-save.services.api.unity.com/v1/data/projects/{PROJECT_ID}/players/{player_id}/items"
    2. r = requests.get(get, headers=header)
    3. print(json.dumps(r.json(), indent=2))
    4. // output is as expected
    HOWEVER, the player does not appear in the player search, from the perspective of the unity web UI, they are a ghost player. This doesn't bother me at all, but my question is, will UGS ever auto delete this player?

    The reason I am using this fake document is that I basically want to store some documents that are not actually specific player related, rather they relate to the status of servers. I could just use Firestore, but I am lazy, and if there is no problem, then Cloud Save is fine for me. I just want to know if UGS will ever automatically "clean up" these spurious player documents.
     
  2. EmilF_Unity

    EmilF_Unity

    Unity Technologies

    Joined:
    Jun 10, 2022
    Posts:
    16
    Hi jackward84, for saving data against non-player IDs I would recommend using the new custom data API documented here:
    Code (CSharp):
    1. bearer_token = get_access_token()
    2. custom_entity_id = "abcd"
    3. url = f"https://cloud-save.services.api.unity.com/v1/data/projects/{PROJECT_ID}/custom/{custom_entity_id}/item-batch"
    4. header = {"Authorization": f"Bearer {bearer_token}"}
    5. r = requests.post(url, json={"data": [
    6.     {
    7.         "key": "Kills",
    8.         "value": 111
    9.     },    {
    10.         "key": "Deaths",
    11.         "value": 111
    12.     }
    13. ]}, headers=header)
    This feature is currently only available through the API and the Cloud Save SDK for Cloud Code v1.3 but we are working on bringing it to the dashboard and the Unity SDK.

    Hope this helps :)
     
    jackward84 likes this.