Search Unity

How can i make the game keep running in the background on android

Discussion in 'Android' started by Michelle_Ca, Oct 4, 2019.

  1. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Hi i'm working on a simulation game, like Sims and SimCity etc.. where player builds a city or people whatever, and then comes back next day to get his income etc..please any help
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Use server, or use OS clock.
    Don't ask user to run app in background.
     
    Michelle_Ca likes this.
  3. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Thank you! I plan to create a multiplayer game and I will use the PlayFab server to store players' data and so on. The only problem is that the method of collecting money or gold in the game is through workers who do a movement and transfer between two building, there will be many of them for each player,and there are also many variables are linked to elements that use OnTriggerEnter To disburse resources and transfer them from one element to another randomly Also the coordinates of the elements (people, animals,etc) and their numbers change depending on the activity
    The game is similar to (The Guild 2, sims,simcity) game
    Do you think running this tasks on the server will not be expensive for the number of players may exceed 100,000?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    "Expensive" is relative term, to how much you make from the app and which online service you will utilize.
    Asking / forcing user to run app in background, you are risking (most likely) negative bomb reviews. That will kill your app and eventually any potential revenue.
    Also, if you allow to relay on mobile device, while game suppose to be online, you are opening path to cheaters.

    If you are concerning of cost, of running task on the server, you may need consider different solution, which may be cheaper to execute. At the end of the day, you need test you solution and see how it perform in real time.

    You could consider to run beta testing campaign, or something similar.
     
    Michelle_Ca likes this.
  5. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    You're right, that might make people get off the game,
    Can I just prevent the game from stopping when I open another app with the game or lock the device?
    its ok to stop when close the app or internet connection
    I will make the game work on the server, but I do not want to disconnect the player once the device is locked, for example
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    You could look into background services solutions for android.
    This topic is asked quite often on Unity forum.
     
    Michelle_Ca likes this.
  7. alex1st1

    alex1st1

    Joined:
    Jan 26, 2019
    Posts:
    275
    You may do it on server in simple way: calculate not actual worker movements , but average, eg: each avg worker does X surplus in one hour, player has y workers, so in z hours he will get surplus= x * y * z
     
    Michelle_Ca likes this.
  8. alex1st1

    alex1st1

    Joined:
    Jan 26, 2019
    Posts:
    275
    And you may do the same on mobile after awake from sleep
     
    Michelle_Ca likes this.
  9. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Hi ,thank you ! it's a good idea , The only problem is that the movement of workers is a little random, where there can be only one worker in some times and the rest of the workers participate randomly after a (random time) where it is difficult to take an average of calculations or predict it is look like hives and random movements
     
  10. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    I am planning to do another solution and have come up with some solutions :
    Calculate the game changes fast in loading screen before game start by
    -"unbind view, recalculate models, bind view back"
    - or update time component few times
    - or push few values to time thread.
    what i need to separate architecture to Data/Logic/View layers and after game resumes update only Data/Logic layers

    I'm just looking for a source to explain these methods or any educational reference. Do you have any idea about that?
     
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Regarding random, you can use seed. But for that, you need have deterministic mechanics, if you would like reliably gas forward for example.

    Stil, your solution is open for cheating. For example simple is time change. Many mobiles game 'suffers' for that reason.
     
    Michelle_Ca likes this.
  12. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    I will use the server time and not the mobile time in addition to storing data before shutdown and evoke when running the game from the server
    Do you think there'll be a chance to cheat?
     
    Last edited: Oct 10, 2019
  13. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    I mean, there is always way, chance to cheat. But you can reduce it greatly on different way.

    As long you check game states with server states and confirm any critical actions with server, you would be rather safe. At least for major cases.

    So if you want to buy unit for example, you should receive confirmation from the server, that such action is legal.

    If you start app on mobile, you should retrieve states from the server. Or if deterministically gas forward, you need confirm game state with server. For example confirm current random values/hash. If there are differences, notify about desyncing, or simply request update from the server.
     
    Michelle_Ca likes this.
  14. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Thanks alot ! i will pay attention to that