question

brendan avatar image
brendan asked

Sync offline save data

Question from a developer:

What's the best way to use offline storage and keep data consistent with that in the player account in PlayFab?

 

10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

The thing you'll need to decide for offline is how secure you want the game to be. We've got studios who go across the spectrum on this. Some examples of possible implementations would be:

  • [No security] Accumulate the data on player actions locally, aggregate the changes, and then upload the data for saves, stats, etc., when the player comes back online.
  • [Some security] As above, but use Cloud Script to check the values and make sure that what the player is saying he did is reasonable.
  • [Better security] Have a custom game server which evaluates the offline data, so that you can do deeper evaluation than would be possible in a Cloud Script (up to possibly simulating the play based upon saved move data from the player).
  • [Best security] Offer a different play mode while offline which does not impact the data/stats for the main game, so that there isn't even an option to cheat the game and get an advantage over other players.

Basically, if you're storing data on the client for a later sync, you can be guaranteed (for any non-trivial user base) that someone will modify that data to cheat the game. Realistically, there's no way to prevent that. So the key is, how important is it to prevent that behavior? In some cases it's not at all, while in others it's absolutely critical.

But in terms of the sync with PlayFab, what you don't want to do is store every change and try to then make a call for every one of them - that would push the client into making far too many calls in a short period (potentially causing the client to be throttled or temporarily blocked). What you'll want to do is aggregate the info on the changes, and minimize the calls. So for example, all the statistic changes can be aggregated and sent as a single API call. The same is true for User Data, for the save info.

Finally, in addition to (obviously) not considering the data "in sync" until you get a good response, you'll have to account for the case of a player who plays on two different devices, one in an offline state while the other is online. So the first thing to do when you log in, if the client has a local save that needs sync, is to get a User Data (or User Read Only Data) key which is always updated when there's a save. Check the timestamp on that (all user data is timestamped) and compare it to the start time for the offline data. If the data on the service is more recent than the start of the offline data, you have a choice - again, based on your game's requirements:

1. Present some kind of summary for each, and ask the player to pick which one they want to keep. Note that if you're using Sum, Min, or Max aggregation on any of your statistics, this will require you to do additional work to make sure this isn't a cheat vector.
2. Reject the locally stored data, and explain to the player that there's a more recent save online.
3. Aggregate the info between the current online save and the offline save. Usually not an option, since this creates an easy cheat vector unless you do all the work to integrate the two in a legitimate way.

3 comments
10 |1200

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

fourmi4x avatar image fourmi4x commented ·

Hi,

Amongst the 6 ways described here : https://stackoverflow.com/questions/34426570/best-way-to-save-data-in-unity-game

=> what would be the best way to save data locally so that' it's very easy to push/retrieve data from PlayFab with your API ?

For instance, what would it take if we are using PlayerPrefs ?

Thank you !

,

Hi, when you say "What you'll want to do is aggregate the info on the changes, and minimize the calls. So for example, all the statistic changes can be aggregated and sent as a single API call."

=> I was wondering, what's the best way to save data locally in Unity to make it very easy to push/retrieve data from PlayFab ?

In this topic I can see there are up to 6 ways of saving data locally in Unity : https://stackoverflow.com/questions/34426570/best-way-to-save-data-in-unity-game

Does one of them make this synchronisation easier ?

For instance, what would it take to synchronise PlayFab with PlayerPrefs data ?

Thank you !

(As you will have noticed, I'm still very new to Unity, I'm just trying to choose the right methodology to have something "compatible" / easy to integrate with PlayFab)

0 Likes 0 ·
brendan avatar image brendan fourmi4x commented ·

Actually, that article would only confuse you if you're starting out. In it, 1 and 2 are just talking about saving data locally, 3 talks about saving to a server (as in our service), 4 and 5 talk about save format for ease of use, and 6 refers to using a local database.

If you're using Unity, then yes, PlayerPrefs is usually fine. The format for the save data can be whatever you need. JSON is very handy as a way to express complex data, so I'd recommend learning to use it for your projects.

1 Like 1 ·
fourmi4x avatar image fourmi4x commented ·

OK thank you for this answer!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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