Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Cloud Save data only accessible by server code

Discussion in 'Cloud Save' started by panderson9149, Feb 12, 2023.

  1. panderson9149

    panderson9149

    Joined:
    Nov 26, 2020
    Posts:
    6
    Is there a way to create Cloud Save data that can only be accessed by Cloud Code script? Such that client code can not access (alter) the data and instead can only interact with the data through a cloud code API.
     
  2. devingunity

    devingunity

    Unity Technologies

    Joined:
    May 26, 2021
    Posts:
    33
    Hi panderson! We're actually just rolling out our new Access Control API, which can be used to control access to various resources, in this case disabling write access to Cloud Save.

    The documentation and CLI support are currently in development, but we do have public documentation for the Access Control API, which can be called using Service Account authentication.

    As a more specific example for your use case, the following HTTP request would disable write access to Cloud Save by players:
    Code (csharp):
    1. curl -X PATCH https://services.api.unity.com/access/v1/projects/{projectId}/environments/{environmentId}/resource-policy \
    2. --header 'Authorization: Basic YOUR_ENCODED_API_KEY' \
    3. --header 'Content-Type: application/json' \
    4. --data-raw '
    5. {
    6.     "statements": [
    7.        {
    8.                "Sid": "deny-cloud-save-write-access",
    9.                "Effect": "Deny",
    10.                "Action": ["Write"],
    11.                "Principal": "Player",
    12.                "Resource": "urn:ugs:cloud-save:*"
    13.        }
    14.    ]
    15. }'
    Here you would need to insert your projectId and environmentId, and use the Service Account authentication as linked above in the Authorization header. Then the policy will deny write access to all players, for any route belonging to the Cloud Save service.

    Note that this would disable player write access to all data in Cloud Save, and so all writes would have to go through a server-authoritative solution (e.g. Cloud Code) - the Cloud Save team is currently working on solutions to make more fine-grained access control possible!

    Please let us know if you have any questions about this functionality, and we are aiming to have the documentation and CLI available soon!
     
    Laurie-Unity likes this.
  3. panderson9149

    panderson9149

    Joined:
    Nov 26, 2020
    Posts:
    6
    Thank you. I will look into this. I have another question. I would like to have a data file on the server that is shared by all players and used in a a cloud code script. It seems I could have a large JSON object in a cloud script and then simply use that object as needed. Is that a recommended method? Is there limits on size of cloud scripts? Is there another means to have a data file/object in the cloud that the cloud scripts can access and use?
     
  4. devingunity

    devingunity

    Unity Technologies

    Joined:
    May 26, 2021
    Posts:
    33
    Hi panderson, depending on the size of the data, you have a few different options:
    • For JSON less than 10,000 total characters, you could store the configuration in Remote Config, and then retrieve it in Cloud Code using the Remote Config Cloud Code SDK - this would allow you to update the value from the Dashboard as needed.
    • Cloud Save can store values up to 5MB, which could then be accessed as above.
    • Cloud Code scripts can be up to 131072 characters, so depending on the script and the data you could store it in the script, but this would of course become difficult if you then wanted to use the same value somewhere else as well, which is why persistent storage like Remote Config or Cloud Save may be more effective.
    We are also currently working on a solution to add file-based storage to Cloud Save (in addition to the key-value storage it currently offers), so keep your eyes open for that if you think that would suit your needs! Sadly I can't give you a timeline on that feature at the moment though.
     
  5. Mid_plays

    Mid_plays

    Joined:
    Jan 26, 2022
    Posts:
    22
    Well I actually have two questions I know it's probably something obviously but I can figure out anything
    1. How can I run a pice of code if the player has a certain inventory item from unity economy and how do I get a specific inventory item

    2. How can i get and set a bool value from unity cloud save and set it to a local bool variable