Search Unity

How To Sync Content For Both Client and Server?

Discussion in 'Multiplayer' started by Alectora, Apr 28, 2017.

  1. Alectora

    Alectora

    Joined:
    Nov 18, 2012
    Posts:
    8
    Hi,

    I'm currently making a multiplayer online game. The game involves collecting pets, and the pets can be used as part of the game (like using pet's special skills). The pets are to be stored in server-side database, not client-side. The number of pets should gradually grow over the time as content updates.

    My question is what's the best flow to sync these data for both client and server? The client needs to have latest pets including the images and stuff related for the visuals. The server also need to know what are the new pets and what it can do for the game.

    It would be funny if the client gets the data and the server cannot acknowledge it, or the server tells the client that there's a new pet to get or display but the client doesn't know what it is.

    My first thought is having both accessing the database for both client and server as needed, then the client always check for new list of pets and download the contents based on that before the application begins. But I'm not sure. I don't even know how to relate it with AssetBundle, if possible.

    Just additional note, the game is HTTP based.

    Thanks.
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    Check out unity's asset bundling feature. The idea is, you can "import" unity-related objects into the game at run-time, if they have been previously bundled up into an "asset bundle". So for example, you could place all of your textures/shaders/scripts/other unity-related object into your asset bundle, and rely on that to provide the content.

    Some additional notes about asset bundling:
    • You need to upload the asset bundle files to a remote server or public cloud storage (dropbox, google drive etc)
    • When you download the asset bundle, it is stored in the devices persistent memory to cache the asset bundle for later use (basically meaning that you only download it once).
    • To download the asset bundle, you'll pass the url of the asset bundle and the version of the asset bundle to WWW.LoadFromCacheOrDownload. If you pass a new version into the method, the asset bundle is downloaded again. So this allows you to store an integer representing your asset bundle version within your code and update this when you want the client/server to re-download the asset bundle
    Hopefully this helps. Good luck!
     
  3. Alectora

    Alectora

    Joined:
    Nov 18, 2012
    Posts:
    8
    Thanks for the reply. But that one is for client-side only right? I need to sync the pets to my game server as well (the HTTP server, bundled with the game server). I need to update the game server with the latest number of pets. The game logic is all done in the game server side.

    What I was wondering is how to match/sync them. Say I put new 20 pets to the servers to be acknowledged. Then I add stuff for the client-side too (in a form of asset bundle). But then say I don't like one of the pet then remove one from the server (makes it 19), and I forgot to adjust the client-side version, stating it has 20 pets, it would be wrong right?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    There's lots of ways to do it.

    You could create a new build any time you add new pets to the game. You'd push the new build to services like GooglePlay and update your server at the same time. Clients would be required to update their build to continue playing the game.

    You could also do this by importing images and pet stats from a folder on the server, and transfer any new information to the clients, all without a new build.
     
  5. Alectora

    Alectora

    Joined:
    Nov 18, 2012
    Posts:
    8
    That would do, Joe.

    Thanks guys.