playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.43k stars 952 forks source link

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

Open Goisak100 opened 2 years ago

Goisak100 commented 2 years ago

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?

KyryloKuzyk commented 2 years ago

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