question

teemu-sillanpaa avatar image
teemu-sillanpaa asked

Uploading file to PlayFab when the application shuts down?

Calling the upload method on OnApplicationQuit/OnApplicationPause works fine, but the stream seems to shut down after the application closes and the file isn't uploaded. Would there be a way to enforce that the player file is uploaded when they exit the application, or would it just need to be uploaded periodically throughout the game session instead?

I'm aware that the OnApplicationQuit methods aren't guaranteed to be called in case of crashes etc. but let's set that aside for now.

Thanks in advance!

10 |1200

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

Seth Du avatar image
Seth Du answered

No sure what genre of game you are developing now but in my point of view, we don't recommend constantly updating player data. It will be better to make the update action event-triggered. Take a turn-based strategy games as an example, you may do a update call every time the player’ turn is over. As a result, even when the client is crashed, the worst thing can be only lose the record of one turn. If it is a match-based game, you may only update after the match is done.(of course verification data before update the data is important) The thing is you don’t have to guarantee players’ data is completely unlosable and basic insurance will do the good. Meanwhile, if it is real-time multiplayer game, this is completely different. Some of the data can be handled on the host server.

Uploading a large file will take time and be aware not to exceed the API waiting time. Caching all calls locally in a queue will also be a work around solution.

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

teemu-sillanpaa avatar image teemu-sillanpaa commented ·

Thanks for the reply!

It's a mobile idle game so there's a lot happening at all times. Upgrades, unlocks and most frequently money income which is happening non-stop. There's not a whole lot of data, we have it split to around 30 separate JSON files which total to around 2.5kb of data when combined, which is what we're doing right now to handle the uploading of player data. Perhaps there would be a better way to save and load the data than writing it to a single object and sending it to PlayFab as a single file?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ teemu-sillanpaa commented ·

Basically it depends on your preference, try to make use of currently existing features. For example, money and unlocks(items?) you have mentioned should be handled by the Virtual Currency feature and Catalog feature of PlayFab.

Uploading separately and combining them into single Json both have pros and cons. As PlayFab is a service based on RESTful API and there is limit on the frequency of calls, I will suggest you to use single JSON, which can reduce the frequency. (Still I can say that if you upload 30 files in a very short time, error will occur)

0 Likes 0 ·
teemu-sillanpaa avatar image teemu-sillanpaa Seth Du ♦ commented ·

How often would be too often to upload that 2.5kb file? I guess it would be occurring much too often if I uploaded the file any time any of the data in those 30 JSON files changes. The uploads would be pretty much persistent. Maybe if I waited for X objects values' to change before combining the files into a single object and uploading it.

0 Likes 0 ·
Show more comments
Show more comments
brandon@uprootstudios.com avatar image
brandon@uprootstudios.com answered

What's your client platform? If it's a non-mobile platform like Windows/Mac/Console, it should be relatively easy to wait for the upload to finish before continuing with Application.Quit. Although if it's iOS or Android, if the user goes to the home screen you might be able to continue network activity in the background for a short period of time, but if they kill the app with task switcher you likely won't be able to do anything after the app begins shutting down.

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

teemu-sillanpaa avatar image teemu-sillanpaa commented ·

We're developing in Unity for Android. That would've been relevant to mention in the OP, sorry about that.

So there's no way of making sure that the data is uploaded when the user leaves the game, then? Would you have any suggestions on how often we should be uploading player data? There's a fair amount of it and it's constantly changing, so what might be good practice here to avoid data loss (or at least minimize it) in worst case scenarios all while not congesting the network with too frequent uploads?

Thanks!

0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com teemu-sillanpaa commented ·

If you're strictly using Android, you can try running the upload as a Service, although I'm not entirely sure how you'd implement that with Unity. Otherwise, I'm not too sure on what the best process is. I don't have a lot of experience with Android or Unity on Android. What kind of data are you trying to frequently upload?

0 Likes 0 ·
teemu-sillanpaa avatar image teemu-sillanpaa brandon@uprootstudios.com commented ·

Player data. General progress such as currency amounts and different unlocks.

0 Likes 0 ·
Show more comments
Show more comments

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.