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

Resolved Usage of other services from within Cloud Code.

Discussion in 'Cloud Code' started by OddOwlI, Jan 15, 2023.

  1. OddOwlI

    OddOwlI

    Joined:
    Jun 5, 2022
    Posts:
    9
    I was looking where I could optimize some places where I am doing multiple UGS calls at basically the same time and turn them into a single Cloud Code batch call.

    This has the obvious benefit of a single call over the web. However it got me thinking about usage of other services from within a cloud code call.

    For example if i do....

    Code (JavaScript):
    1. const cloudSaveApi = new DataApi({ accessToken });
    2. cloudSaveApi.setItem(projectID, userID, 'thekey', 'theval');
    3. cloudSaveApi.setItem(projectID, userID, 'key2', 'val2');
    Now this is a bad example because of the existence of the setItemBatch call, and i am assuming it would count as two reads from your Cloud Save Read total.

    Is my assumption that the usage is the same if you make the calls from inside the game vs inside a cloud code script? Is it true for all services?

    Thanks
    ~Chris
     
  2. Unity_AndyP

    Unity_AndyP

    Unity Technologies

    Joined:
    Jun 23, 2021
    Posts:
    65
    Hi Chris,

    Yes, you are exactly right. If you make a call to another service through cloud code then it will add to your usage. exactly the same way as if you were doing it from the client such as to Cloud Save or Economy. The batch method is definitely good practice when using your example to reduce the usage counter for certain checks.

    For others curious about the batch method you can find more info here.
     
    Last edited: Jan 16, 2023
  3. OddOwlI

    OddOwlI

    Joined:
    Jun 5, 2022
    Posts:
    9
    Thanks for the info.