Announcement

Collapse
No announcement yet.

Replication pain and suffering. Multiplayer for dummies.

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

    Replication pain and suffering. Multiplayer for dummies.

    One huge part of the engine was not touched by me long time before. And now after a week digging in, I realized that something is VERY wrong with multiplayer. I will show you how the most trivial task becomes a nightmare when you try to implement it in server-client configuration.

    Task: set random color for every character. Setup - listen server and two clients.
    Click image for larger version

Name:	2017-09-16_19-31-30.png
Views:	1213
Size:	570.7 KB
ID:	1354877

    If you are beginner you probably just try something like this:
    1) Generate random color on server.
    2) Set color to Character which replicates by default.
    Click image for larger version

Name:	2017-09-16_20-18-12.png
Views:	1213
Size:	150.5 KB
ID:	1354879
    I imagine that almost every beginner thinks that replication is the magic wand, so all you need is to set replicates on every actor you want to see on clients, but it doesn't work like this.
    Click image for larger version

Name:	2017-09-16_19-59-04.png
Views:	1196
Size:	619.1 KB
ID:	1354880
    And somehow you need to understand this by yourself in hundreds experiments.


    In fact you should keep in mind a lot of information to make something working.

    First of all this diagram from wonderful eXi's network compendium:
    Click image for larger version

Name:	2017-09-16_19-45-32.png
Views:	1208
Size:	134.8 KB
ID:	1354878

    It describes object existence in every instance. By the way there are 3 actually levels, each on every "PC". We will name them ServerWorld, World1 and World2. Before I just set colors for characters in ServerWorld.

    So as you can see there are actually 9 characters overall. 3 for every world. But I'm sure you already read somewhere that server controls only movement. To set the exact color for every character you should:

    1) Generate random color and save it on server in object existed on every instance. PlayerCharacters (pawns) fit this task. You can also use PlayerStates or GameState.
    2) Call function on every instance for every character to set the color using saved value from server. Value should be replicated.

    Blueprint:
    Click image for larger version

Name:	2017-09-16_20-44-50.png
Views:	1182
Size:	184.2 KB
ID:	1354882
    Did I promise pain before? Here it is!
    Click image for larger version

Name:	2017-09-16_20-40-31.png
Views:	1154
Size:	623.1 KB
ID:	1354881
    It doesn't work! Lol. You should wait while value replicates to every instance (even if it's the same computer, sick!). And 0.2 sec delay is not enough! Put 1 sec delay before calling multicast event and finally you could set correct colors on every instance.

    Btw, I found the RepNotify pretty easy way to use in this case. You don't need to think about delays at this point.

    Click image for larger version

Name:	2017-09-16_20-50-39.png
Views:	1179
Size:	166.4 KB
ID:	1354883
    Click image for larger version

Name:	2017-09-16_20-52-37.png
Views:	1180
Size:	75.0 KB
ID:	1354884

    Ok. It's tricky but kinda easy when you work with Character, because it exists ns on every instance. Roughly speaking Player1 can do stuff in World2. But in big projects usually PlayerController is the main class you working with. So if you want to make same task with colors but using PC next list for you:

    1) You call the server event on PC that will generate random color and save it in gamestate because it exists on every instance and PC doesn't (you can read variables from PC only on the server).
    2) You call the multicast event on the gamestate and send your pawn to it. You can only call this event from server!! So Gamestate will call SetColor function for exact pawn in every world.
    Click image for larger version

Name:	2017-09-16_21-05-36.png
Views:	1181
Size:	87.2 KB
ID:	1354885
    Click image for larger version

Name:	2017-09-16_21-05-13.png
Views:	1178
Size:	130.5 KB
ID:	1354886
    Or even more often situation:
    Click image for larger version

Name:	2017-09-16_21-15-28.png
Views:	1215
Size:	154.6 KB
ID:	1354887

    And all this just because actors don't replicate their parameters. The end.
    Available for contract hiring! Complex mechanics, quick game prototyping, VR, AI, Animation, Tools for designers.

    Check out my latest game! Last Joy - 2D RPG with unique combat system.

    #2
    It took me 6 months digging in multiplayer to get it how it works...
    Begin play cannot work without delay because it + -starts with server, but when server creating game, it can take a while when other players get connected.

    Im not sure if your post is question, tutorial or complaint, but i found ue4 mp working well (but ofc there are some bugs).

    Comment


      #3
      I wish this post was made 6 months ago when I was playing with replicated morph slider values. After all of the pain and suffering, I finally understood how RepNotify had to be run on the server for it to replicate to everybody else. What a headache

      Comment


        #4
        I wouldn't want to be in your shoes, guys) I only spent a week figuring out how MP should be setup basically and I hope my "guide" will help someone else to avoid unnecessary loss of time.
        Available for contract hiring! Complex mechanics, quick game prototyping, VR, AI, Animation, Tools for designers.

        Check out my latest game! Last Joy - 2D RPG with unique combat system.

        Comment


          #5
          Another tip for multiplayer diggers. Wait 2 frames before you attach the spawned actor.

          https://answers.unrealengine.com/que...awning-to.html
          Available for contract hiring! Complex mechanics, quick game prototyping, VR, AI, Animation, Tools for designers.

          Check out my latest game! Last Joy - 2D RPG with unique combat system.

          Comment

          Working...
          X