question

ffpang88 avatar image
ffpang88 asked

[Unity] Lag between player logging in and cloud data downloading

I am having difficulties trying to get cloud data. The data saves to the cloud correctly, loads from the cloud correctly, but because I attempt to get any data immediately after the player successfully logs in, the cloud does not download quick enough to be accessed. Which callbacks can I subscribe to so I can make sure that the data is ready before I access them? e.g. The data is either successfully loaded from cloud, or is determined that there is no change to the data that is already stored locally.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Ffpang88, Thank you reaching out and sorry for the delay to answer the query. I think you need to understand the offline scenarios of Whispersync. Unlike the GameCircle leaderboard and achievements clients, the Whispersync client is available immediately after initializing AmazonGamesClient. Whispersync data is always accessible, even when the player is not registered with Amazon or is offline. So at any point in the app you may get access to Game Data but not necessarily you will always get data from cloud. In order to make sure that the data is from cloud you should follow below flowchart. You need to write your app to synchronize the calls to GameCircle plugin in a sequence. Call to GameCircle init() -> get callback to onServiceReady() -> register whispersync callbacks -> check whether user is signed in by using Player.isSignedIn() If player is signed in, call WhispersyncClient.synchronize() -> get callback on onNewCloudData() -> access GameData for latest cloud values If player is not signed in, do nothing, wait for user to signin -> when user signs in -> get callback on onNewCloudData() -> access GameData for latest cloud values In Unity the code flow should be below AGSClient.ServiceReadyEvent += ServiceReadyHandler; AGSPlayerClient.PlayerReceivedEvent += PlayerReceived; AGSPlayerClient.OnSignedInStateChangedEvent += OnSignedInStateChanged AGSWhispersyncClient.OnNewCloudDataEvent += OnNewCloudData; AGSClient.Init(usesLeaderboards, usesAchievements, usesWhispersync); private void ServiceReadyHandler() { AGSPlayerClient.RequestLocalPlayer(); } private void PlayerReceived(AGSPlayer player) { if(player.IsSignedIn){ AGSWhispersyncClient.Synchronize(); } } private static void OnSignedInStateChanged (Boolean isSignedIn) { if(IsSignedIn){ AGSWhispersyncClient.Synchronize(); } } private void OnNewCloudData() { //This dataMap would have data from cloud AGSGameDataMap dataMap = AGSWhispersyncClient.GetGameData(); } Does it make sense?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.