Announcement

Collapse
No announcement yet.

How to best design my game for a multiplayer / replication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to best design my game for a multiplayer / replication

    Hi Folks,

    I started converting my game from offline to multiplayer and I ran into a question around how to best structure my game given replication and multiplayer.

    My game is procedural generated and so maps are generated based on a seed. The question I have is regarding how to best structure my game so that when players join the game they get the generated map and have everything ready replicated locally before they can spawn.

    As a first attempt I was replicating all tiles from the map as well as the location of the spawn points, enemies, etc. The issue I face is that I can't really tell when everything has been completely replicated and so I see that my game tries to spawn before the spawn positions have been replicated for example.

    I tried adding a boolean flag that is replicated so that I know when the map has finished generating on the server and this helps in the listening client but it doesn't help the player that joins later.

    Any tips on how to best structure this or on ways you guys solved a similar problem where you need to make sure everything replicated before 'starting'the game for the clients?


    Regards,

    Seb

    #2
    Hi, some questions so I can better understand your setup:

    My game is procedural generated and so maps are generated based on a seed.
    (1) Can your map change during the game, or is it static after the initial spawn?

    (2) Also with based on seed, does that mean that it is not really random, so if you would both times use the same seed would that both times give the same result?

    Comment


      #3
      Hi chrudimer ! thanks for following up.

      1) Yes, the idea is that the tiles can change (for example based on the damage they take)
      2) And yes, the other approach I could take is to generate the map on every client instead, but that sounds like it would be a lot riskier to keep tiles in sync across clients would it not? What I thought was that by generating the tiles (actors) and replicating them all I needed was to apply changes to the tile once and it would then be replicated to all clients.

      This is the first game I am making so a lot of ramping up is needed hence asking questions around what have been people's experience on this sort of scenario to understand better how to re-structure my game.

      Comment


        #4
        On the particular tile damage example, let' assume one of the tiles is a bridge, if enough damage is done the bridge breaks and so the players cannot go through it.
        If I create the tile once and replicate I know they all will have the broken bridge. But If I go down the path of generating the same bridge on both clients I then need to make sure that every damage done is also done on both clients the same way. This last bit feels like it can be tricky, or maybe it sounds like it due to my lack of experience at this stage.

        Comment


          #5
          1) Yes, the idea is that the tiles can change (for example based on the damage they take)
          Ok, then I would first try the approach you're using, so replicating everything (unless you have problems with server CPU performance due to replication or network bandwidth problems then you might need to optimize further).

          When a new player joins the game (so for example in the event begin play of the player controller, or where you're handling join of a new player), then on the server get the class and amount of all replicating actors and send that info to the newly joined player. So use "get all actors of class" for each replicating actor you have and send the class and amount over to the newly joint player (I would use a custom struct for this containing an actor class and an int and send an array of this struct over to the newly joint player via reliable RPC or make the array repNotify).

          Then on the newly joint player use a timer to compare the amount of actors in his world, with the amount the server has sent over. So for each loop over the array from the server -> "get all actors of class" using the class from the struct -> compare the amount with the int from the struct.

          When you compare the amount, I would not check for exact equality since the game is continuing to run on the server during client load and therefore the numbers could change somewhat.

          Comment


            #6
            Hi chrudimer , Sending the count of each class is a really clever idea and it could work, ideally I would only really need to make sure that tiles and enemies are done, the spawn point is just a transform to a point on the map so as long as the tiles are there I should be good. I'll give that a shot!

            Thanks heaps for the input.

            Seb.

            Comment

            Working...
            X