New To The Forum? Click Here To Read The How To Guide. -- Developers Click Here.

Is it safe to call CloudStorage.Save in OnApplicationQuit?

AlanLiuAlanLiu Posts: 6
NerveGear
I'm using Unity engine with Oculus Platform SDK. And I'm curious about if I call CloudStorage.Save in OnApplicationQuit, then exit game immediately, can cloud storage be updated correctly?

Comments

  • imperativityimperativity Posts: 1,711 Oculus Staff
    Hi,

    Welcome to the Oculus Developer Forums.

    Based on how this is called and processed on our system, this would not save correctly as `CloudStorage.Save` and `CloudStorage.Load` are of type `Request<>`. They both have a method called "OnComplete", which takes a delegate (or a callback) to be executed once the request has finished.

    Since you would be quitting immediately after calling this, you would not get the necessary call back on completion.
  • AlanLiuAlanLiu Posts: 6
    NerveGear
    Thank you for the reply. If I'm not concerned about the completion callback(result), can I quit the game immediately after calling Save? I want to do this, because I observed that waiting for saving cloud storage may cost dozens of seconds when quit the game.
  • imperativityimperativity Posts: 1,711 Oculus Staff
    @AlanLiu

    From the documentation:

    The following SDK methods can be called from your client app:

    • Save a blob:

      Native - ovr_CloudStorage_Save()

      Unity - Platform.CloudStorage.Save()

      Data is stored as an opaque binary blob, review the ovr_CloudStorage_Save page for information about the parameters and return data structure.

      This call sends the blob data to the locally running Oculus process and will not trigger network calls. Network synchronization happens when the App is no longer running. Total size for a blob can not exceed 10Mb.

      Note: It is important, when sending a cloud save, that a local copy of the data is maintained until confirmation is received that the cloud save was successful. If an error occurs, the data contained in the request will be lost and you'll need to try again.
    Basically, yes---you can do this, but there is a chance that quitting before confirmation will result in your data being lost. Proceed at your own risk.
  • AlanLiuAlanLiu Posts: 6
    NerveGear
    OK, I see. Thank you for your help.
  • PeajPeaj Posts: 1
    NerveGear
    As this is no satisfying solution for me I have to revive this Topic.

    How should I properly save the game state before the game quits?
    Right now I just syncronously load the game in Awake and synchronously save the game state in OnApplicationQuit.
    This works great with local files or other Cloud save sdks.
    In this case it is totally desirable behaviour to block execution unitil the game is fully loaded or saved. But it seems like the Oculus SDK misses a synchronous solution.

    As I have no other indication of when the game quits then the OnApplicationQuit method (because there are multiple different ways to quit the game) it seems to be the right place to save the last state of the game before quiting.
    Is there any way to make the call synchronous or wait until it is completed?
Sign In or Register to comment.