question

ebrahimB avatar image
ebrahimB asked

Using UpdateUserData to save data does not work when quitting app

Hello,

 

I checked the forums but couldn't find anything related to my issue. I am having issues saving game data in Unity3d. In our game we save our app once it is quit by the user (i.e. OnApplicationQuit()). The issue is that we do not see any data on the user in the dashboard. We have tested saving in other locations and it does work. It just seems that saving in OnApplicationQuit() or OnDisable() won't work. Here is the code I am using to save the data: 

private void CloudSave(string pJsonData) {
     UpdateUserDataRequest request = new UpdateUserDataRequest() {
          Data = new Dictionary<string, string>(){
               {PATH, pJsonData},
          }
     };
     PlayFabClientAPI.UpdateUserData(request, (result) =>
     {
         Debug.Log("Success!");
     }, (error) =>
     {
          Debug.Log(error.ErrorDetails);
     });
}

 

My question is, is that by design? Is there a way to save the user data before the user quits the app? 

 

Note: I have been testing this in the editor but have not tried it on a device. 

10 |1200

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

brendan avatar image
brendan answered

We actually don't control when your title sends messages to our service, nor do our API calls have any state information on your title, apart from the player's logged in state, so you can expect that any UpdateUserData call which is successfully made by the client to PlayFab will update the user data - there's no way for us to differentiate a call coming from OnApplicationQuit versus any other segment of the game logic.

There are two things I would recommend that you try. First, put a breakpoint in your CloudSave logic, to check that everything is going well or, if not, that you know what the error is which is coming back. Second, if it all looks good, use Netmon or Wireshark to check the actual communications.

Also, it's worth noting that OnApplicationQuit, ProcessExit, etc. (depending on which platform you're using) is not guaranteed to be called. An app which is forcibly stopped will not get the opportunity to make this call.

10 |1200

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

ebrahimB avatar image
ebrahimB answered

Thanks for the speedy reply. I have not managed to get it to work. It looks like the method is getting called in the method. I'm still messing around with Wireshark, but haven't made any conclusions on that end. There are still some things I'll try out before I just decide to save the game somewhere else

10 |1200

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

brendan avatar image
brendan answered

It sounds like the message is not being transmitted, one way or the other. If you put a breakpoint into the path for transmitting the POST message to us (MakeRequestViaUnity may be the one you're using currently), you should be able to see whether the message is being transmitted.

10 |1200

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

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.