question

zeenzoola avatar image
zeenzoola asked

Store persistent local data

Hello. I'm new to PlayFab so please forgive me if there's an obvious and easy to find answer to this question.

I have some experience working with AWS Cognito and the way it works is it stores key-value pairs locally in a persistent manner (similar to PlayerPrefs) and then synchronizes them with the cloud upon invocation of the Sync method, where it compares the cloud state with the local state and overwrites the older one with the newer one. This essentially means that all the data can be stored locally even if the user currently doesn't have an internet connection, and it can be synced once the connection becomes available.

When it comes to PlayFab, is there a way to persistently store data in this manner or am I required to fetch it from the servers every time my game starts? If the latter is the case, what is the best way to handle an "offline" scenario?

1 comment
10 |1200

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

zeenzoola avatar image zeenzoola commented ·

Just to add that I'm talking about Unity, of course.

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

So the question is, do we provide offline caching of data updates on the client? No, we do not currently provide an SDK that does client-side caching for later update. We do plan to provide client caching for events in an upcoming release, but caching of all data for later update would be further out.

If you want to allow for offline play, what we would recommend is aggregating the information locally and then updating it the next time the player connects. What you upload and how you want to check that it hasn't been modified by the user locally is going to be fairly game-specific, though.

However, there's no reason you can't keep a local cache of data on the client device. I'd simply recommend having a simple check for a version or similar on game load, so that if the player had progress on a different device, you know to re-download all the state info.

2 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.

zeenzoola avatar image zeenzoola commented ·

Thank you for the answer. It's not strictly about offline play from start to finish either. Since making api calls is something one should not do constantly but only at certain moments in the game, I would have to assume that the following scenario is pretty common:

1. The user has a working internet connection and is playing the game.
2. Before getting the final score, he loses the connection.
3. Finishes play with a high score.

Since the call to update player statistics will fail in this case, the high score won't be saved anywhere and the player's progress will be lost. I can see this problem being pretty common.

I guess would I need to use PlayerPrefs as a bridge between PlayFab data and what is being displayed in the game when it's running. I'm having a hard time imagining how one could completely rely on data being stored online only, without making this in-between system. However, this does add a layer of complexity and a lot of room for potential bugs...

0 Likes 0 ·
brendan avatar image brendan zeenzoola commented ·

Yes, for mobile titles, it's always the case that you have to plan for not being able to reach the Internet at any time (tunnels, etc.). So using local storage as a way to cache information you want to update on the player profile later is indeed a smart approach.

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.