question

kabumere avatar image
kabumere asked

Saving data in Unity on Pause/Quit/Lose Focus

Background (you can skip below to TLDR) as this portion isn't really necessary to answer the question):

Alright so I'm implementing my saving functionality and my apps are being built using Unity.

Although I do not have all the save functionality completed, I'm planning on having critical items like currency being updated through CloudScripts where I can safely put my security checks (if reason for gem increase == anything other than 'store', then values above 1000 are not realistic/allowed, etc) and non-critical items like the Player class serialized JSON (minus currency, stats, etc) being updated through regular PlayerData calls.

There's specific points in my game where I will plan to call these methods like updating currencies after ever run session (it's an infinite runner) or updating currencies after every shop purchase, but I was thinking, if a user or the OS force closes an app, where should I save the data?

I understand OnApplicationQuit isn't guaranteed to be called on some platforms with Unity, so OnApplicationPause seems like the next best thing. But will putting a call to PlayFab in OnApplicationPause issue API calls too frequently? Since OnApplicationPause(true) can be called whenever a person answers a call, goes to their home screen, puts the app out of focus, and OnApplicationPause(false) is called whenever we resume. Currencies probably won't be updated here as the only time they should change are strategic points I mentioned earlier. However some PlayerData key-value pairs will need to be saved on quit/pause.

TLDR)

1) For anyone familiar with Unity, in the case of my app losing focus or being quit, I need to know the best place to issue calls to PlayFab for saving my game data (OnApplicationQuit / OnApplicationPause / etc).

2) Would I go over my allotted amount of API calls too quickly putting calls in OnApplicationPause?

3) Is there a page that tells us clear cut the limits we have each month, or is the only limit being under a certain amount of MAU each month like GameSparks?

apisCloudScriptPlayer DataAccount Management
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 limits for the service are the ones you see in your Settings tab (for total bytes, number of keys, etc.) plus a rate limit for calls, to prevent a title from spamming the service and impacting performance. You should aim to have your call rate be as low as you can make it for multiple reasons. One is, of course, that we'd prefer to keep costs as low as possible so that we can continue to offer the free service, and keep our prices for upgrades and enterprise contracts as low as possible. But another is that frequent calls from a mobile device will drain the battery more quickly - and you might be surprised how irritable that can make people (which is to say, it will cause some abandonment). If you're making a call every few minutes to save, that's not a problem. But yes,we'd definitely recommend saving some data locally, as in addition to not being able to guarantee that you'll get a quit or pause call, you have to account for the fact that even if you do, the player might not have a connection at that point (in a tunnel, on a plane, etc.).

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.

kabumere avatar image kabumere commented ·

Whenever they try to save and they no longer have a connection at that point I switch them to offline mode (which a player can only be in for up to 24hrs and it puts caps on the amount of currencies and items one can gain). When offline is on I save stuff locally.

But it's only if we get an error from PlayFab that I have the game switch to offline mode and save things locally until a connection is found.

My question was more focused on the cases where OnApplicationXXX is called, and the app suddenly quits before the call to PlayFab is even made/in the middle of the call (so my app can't receive the response). I was looking for what to do in these particular situations.

Also, on average by your statistics, about how many monthly users can one acquire before they start to go over the monthly limits?

-1 Like -1 ·
brendan avatar image brendan ♦♦ kabumere commented ·

There is no limit on the number of users - limits are per user.

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]