Cloud Save Query within Cloud Code throws Deserialization Error

I have a Cloud Code module (C#) that needs to query indexed data in Cloud Save.

The setup:

  • I’ve created an index in Cloud Save for “username” key.
  • I have added the username “test” to a player’s default Cloud Save data.
  • I’ve created a Cloud Code module called Friends, written the class below, and generated bindings.
  • Deployed to dev environment and run the test.

Here’s the module code:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Services.CloudCode.Apis;
using Unity.Services.CloudCode.Core;
using Unity.Services.CloudSave.Model;

namespace MyGame;

public class Friends {
  private readonly ILogger<Friends> _logger;

  public Friends(ILogger<Friends> logger) {
    _logger = logger;
  }

  [CloudCodeFunction("TestCloudSaveQuery")]
  public async Task<string> TestCloudSaveQuery(IExecutionContext context, IGameApiClient gameApiClient) {
    try {
      var results = await gameApiClient.CloudSaveData.QueryDefaultPlayerDataAsync(
        context,
        context.ServiceToken,
        context.ProjectId,
        new QueryIndexBody(
          new List<FieldFilter>(){
          new("username", "test", FieldFilter.OpEnum.EQ)
          },
          new List<string> { "name" }
        )
      );
    } catch ( Exception ex ) {
      _logger.LogError(ex.Message);
      return "Bad test";
    }

    return "Good test";
  }
}

The function should query the default player data and get all players with the username “test” (which is just one) and return the “name” (another Cloud Save data item) of that player. However, I get this error logged in Cloud Code logs:

Deserialization of type ‘Unity.Services.CloudSave.Model.QueryIndexResponse’ failed.

If I change the username being searched for to something non-existent (no results), then the query runs just fine, and returns a 0 count result.

I’ve also tried this without specifying the return keys, which is supposed to simply return all the player IDs that match the query, but that gives the same error.

Is this a bug with Unity’s Cloud Save service? Or am I doing something wrong?

Hi Caleb,

Your code seems to be perfectly fine - I’ve done some testing and this appears to be a bug that was introduced in v0.0.13 of the Com.Unity.Services.CloudCode.Apis package.

We’ll look to get a fix out for this soon, but in the meantime if you’re able to downgrade to v0.0.12 of the package I believe your code should work as expected!

1 Like

Just to follow up again, we’ve released a new version of the Com.Unity.Services.CloudCode.Apis package (0.0.15) which includes the fix for this bug.

1 Like