play-games-plugin-for-unity icon indicating copy to clipboard operation
play-games-plugin-for-unity copied to clipboard

Unity's Google Play Game Services(GPGS v10.14) ReadBinaryData() does not run in Task.Run()

Open Goisak100 opened this issue 2 years ago • 1 comments

I am implementing Cloud Save and Load function by linking Unity and Google Play Game Services (GPGS v10.14).

I need to load data from the cloud and process the loaded data into strings. At this time, I used async-await to process it asynchronously because the order is important.

private async void OnLoadData(ISavedGameMetadata metadata)
{
  var savedGame = PlayGamesPlatform.Instance.SavedGame;

  var task = Task.Run(() => savedGame.ReadBinaryData(metadata, OnReadBinaryDataRequestHandler));
  await task;
}

private void OnReadBinaryDataRequestHandler(SavedGameRequestStatus status, byte[] loadedData)
{
}

However, when I call ReadBianryData() with Task.Run(), the program terminates. (Testing results on Galaxy S10 5G)

Why is the program terminated?

Goisak100 avatar May 11 '22 02:05 Goisak100

I believe you have to call this API only from the main thread.

KyryloKuzyk avatar Jun 19 '22 07:06 KyryloKuzyk