Is there a way to load multiple players' PublicData at once?

Is there a way to load multiple players’ PublicData at once?

For example, I want to load the “level” key from the PublicData of players who are registered as friends.

The method I know to implement this is to call the ‘CloudSaveService.Instance.Data.Player.LoadAsync’ function for each friend player.

Is there a more efficient way?

Hi there!

You can find an example of how to do this here:
https://docs.unity.com/ugs/en-us/manual/cloud-save/manual/tutorials/unity-sdk#Query_Player_Data

public async void QueryPlayerData()
{
  var query = new Query(
    // The first argument to Query is a list of one or more filters, all must evaluate to true for a result to be included
    new List<FieldFilter>
    {
        new FieldFilter("indexedKeyName", "value", FieldFilter.OpOptions.EQ, true),
        new FieldFilter("anotherIndexedKeyName", "otherValue", FieldFilter.OpOptions.NE, true),
    },
    // The second (optional) argument is a list of keys you want to be included with their values in the response
    // This may include keys which are not part of the index, and does not need to include the index keys
    // If you don't specify any, you will still get back a list of IDs for Players that matched the query
    new HashSet<string>
    {
        "somePublicKey1",
        "somePublicKey2"
    }
  );
  var results = await CloudSaveService.Instance.Data.Player.QueryAsync(query);
  Debug.Log($"Number of results from query: {results.Count}");
  results.ForEach(r =>
  {
      Debug.Log($"Player ID: {r.Id}");
      r.Data.ForEach(d => Debug.Log($"Key: {d.Key}, Value: {d.Value.GetAsString()}"));
  });
}
1 Like

Thanks but,
This is a little different from what I’m trying to do.
I want to get PublicData regardless of conditions with PlayerID List.

To retrieve the PublicData of 50 friends, I need to call CloudSave 50 times. Is there a way to optimize this process?