Search Unity

Question How to run server code when app isnt running

Discussion in 'Unity Gaming Services General Discussion' started by VagelisGardikis, Feb 16, 2022.

  1. VagelisGardikis

    VagelisGardikis

    Joined:
    Apr 24, 2018
    Posts:
    20
    Hello. Can i somehow run a code from Cloud Code, even when the user isnt using the application?
    I want to run a code several times a day when the player is offline that has an impact on the player's inventory items.
     
  2. tony_c-unity3d

    tony_c-unity3d

    Unity Technologies

    Joined:
    Jul 18, 2019
    Posts:
    35
    One "outside the box" solution would be to run the desired update when the player actually starts playing. We do this in our Idle Clicker Use Case Sample to grant the currencies that would have been generated by 'factories' as they enter the game so it appears that they happened in real time.

    The added benefit to this approach is that you don't have to update players that are not playing and you're guaranteed to have the latest state which is up to date with the moment they started playing. Taking our Idle Clicker Use Case Sample as an example, we needed to call Cloud Code at startup anyway to retrieve the latest state, so we could accomplish everything with 1 call and enjoy a fully-updated game state in the process.

    As for actually running Cloud Code separate from a client, I'll leave that question to the Cloud Code team, but hopefully this approach will get you up and running, and may offer more up-to-date results.

    Hope this helps. If not, or you need any more information, please don't hesitate to reach out. Best of luck!
     
    richj_unity and unity_Ctri like this.
  3. unity_Ctri

    unity_Ctri

    Unity Technologies

    Joined:
    Oct 20, 2020
    Posts:
    81
    Hey Gardikis,

    Like Tony said, it's not out of the box possible at present, but the dev team would like to know more about what you're wanting to achieve, so we can consider that use case during future development.

    If there's more you can share, it'd be quite helpful!