Announcement

Collapse
No announcement yet.

Come Learn Blueprint Multiplayer with me! (aka Tom's a Glutton for Punishment)

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

    Come Learn Blueprint Multiplayer with me! (aka Tom's a Glutton for Punishment)

    Update: Blueprint Multiplayer Movement replication is officially good to go! Here's a shortcut to the tutorial post:
    https://forums.unrealengine.com/show...ll=1#post19427

    Hello intrepid UE4 Blueprinters!
    Welcome to what is assuredly a fiasco in the making!

    I'm trying to make a Blueprint-only multiplayer game. I'm going to start VERY small and try and build from there. I want to share with everybody exactly how, from the ground-up to make an MP game with blueprints. Epic have stated that they want Blueprints to have full network functionality, so here's my personal test-bed for the state of BP MP. I want to share with everybody my journey and get help along the way from those that know multiplayer, replication and anything else better than I.

    About me
    Ive been using UDK/UE3 for years as a tech artist and eventually UnrealScripter. I was invited to the the UE4 beta last year and have spent a fair bit of time in it learning materials, lighting and blueprints. I have a pretty good grasp of all of it, but I've never really tackled multiplayer and replication (it's so scary!). Now I've made a fun game prototype (Drone Wars Extreme! *the name changes daily) and I want to make it multiplayer, but don't want to have to learn C++ to do it. Why? because the game runs great without ANY C++ and I feel that Blueprints are fully capable of creating great games without C++. (Here's a little clip from the other day: https://www.youtube.com/watch?v=eeHsqCM2QyI)

    Where I'm at now
    I've started over for the sake of learning, scrapping all that fancy copter action and going with just a simple Pawn, etc.
    I've created a Blueprint for each of the classes and assigned them accordingly to the gametype:



    Great. You can see I added a big, green arrow to my Pawn (I can see where it is in the world, etc.) There's nothing other than the Static Mesh arrow in there.

    I've also made a simple level that has a few PlayerStarts in it:


    First problem!
    I'm running my multiplayer game from PIE using the fancy Number of Clients setting and a dedicated server (Worst case scenario, ya know?) and immediately, I have a problem. My two players are starting at the same playerstart!


    I don't see any obvious functionality to determine what PlayerStart I should be assigning my players. Also, I'm not savvy enough with networking in UE to even know what class should be handling that sort of thing.

    Can anybody help? Thanks for tuning in! As soon as I figure out an answer, I'll post it here, then on to to the next problem, etc until there's a real, living MP game!

    Files
    Oh, here's the project files. I'll try and update them as we figure all this out:
    https://dl.dropboxusercontent.com/u/..._20140404a.zip
    Last edited by Tom Shannon; 02-02-2018, 04:26 PM. Reason: Updated the link!

    #2
    This is a cool project. I'm going to bump since that's currently all I can do to help.

    +1

    Comment


      #3
      Great stuff, looking forward to watching your progress!

      Comment


        #4
        WOW, that video look's amazing, great job. I'm glad that multiplayer will be supported in Blueprints.

        Comment


          #5
          Good luck Tom!
          Your progress will help me greatly. Also wanted to note that over in another thread Billy Bramer from Epic, when I asked about blueprints stuff for networking 2 days ago, said the following;

          Originally posted by Billy Bramer View Post
          I can answer this one if the stream doesn't cover it. We have a multi-part video tutorial on this coming soon, as well as a sample map like the other ContentExamples. I finished recording the video early this week. It just needs to be prepped and made ready, so it should be ready to go soon!
          So looking forward to that. I think it will help us both.

          PS: Copter game is coming along great, looks fun. I first saw you showing it off on the ol' UDK forums.

          Comment


            #6
            Originally posted by Tom Shannon View Post
            First problem!
            I'm running my multiplayer game from PIE using the fancy Number of Clients setting and a dedicated server (Worst case scenario, ya know?) and immediately, I have a problem. My two players are starting at the same playerstart!
            I don't see any obvious functionality to determine what PlayerStart I should be assigning my players. Also, I'm not savvy enough with networking in UE to even know what class should be handling that sort of thing.
            GameMode.cpp.
            Start by making sure ShouldSpawnAtStartSpot() returns false, then create a custom ChoosePlayerStart().

            The default behaviour is to place spawning players at the first PIE player start it can find or, failing that, just the last player start found.

            You should be able to get what you need by checking out those functions in "ShooterGame\Private\Online\ShooterGameMode.cpp".

            Have fun!
            Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

            Comment


              #7
              Originally posted by Kris View Post
              GameMode.cpp.
              Start by making sure ShouldSpawnAtStartSpot() returns false, then create a custom ChoosePlayerStart().

              The default behaviour is to place spawning players at the first PIE player start it can find or, failing that, just the last player start found.

              You should be able to get what you need by checking out those functions in "ShooterGame\Private\Online\ShooterGameMode.cpp".

              Have fun!

              Thanks for the insight! I was trolling around the ShooterGame example, looking for where that was handled. There doesn't seem to be anything in Blueprints that is analogous. I'll try and make a workaround in the Game Mode blueprint.

              Comment


                #8
                I think I have a working solution for problem #1!

                Using the knowledge that the Gametype was chosing the playerstart for the pawns in ShooterGame, I tried to access the functions being used in C++. No luck. I did however discover that I cannot use the variable names defined in GameType.h (specifically the PlayerStarts array!) But I could use the function names. While it's probably a bad idea, I've done it anyways :P

                Here's how it works.
                When each player logs in, they spawn a pawn. In the Construction Script, I have the BP_MP_Pawn ask the BP_MP_Game GameType to find a PlayerStart actor in the level whose PlayerStartTag variable isn't set to 'Taken' (the only variable accessible for PlayerStarts though Blueprints, and seems to be replicated.*).

                This is accomplished by casting the gametype to BP_MP_Game and running the ChoosePlayerStart function. This function iterates through the PlayerStart actors in the level and compares the value of PlayerStartTag to 'Taken'. If it's not, it breaks the loop, then sets the tag to 'Taken' (so it will skip over it next time), then returns the PlayerStart actor reference to the Pawn that called the function! The Pawn simply takes that data and sets its location and rotation to match the PlayerStart.

                Choose Player Start function (in BP_MP_Game Blueprint)

                BP_MP_Pawn Construction Script


                Here's proof it worked!

                Them pawns be lookin' at eachother!

                Next up:
                Movin' dem Pawns! Stay Tuned!

                *I could create my own brand of PlayerStart actors using blueprints, as there isn't anything particularly special about the class for this examples particular needs, but that's over complicating things... for now...

                Comment


                  #9
                  Awww yiss

                  Okay, I think I may have learned something about replication. Gasp.

                  I got my pawns rotating around. And the SEE EACH-OTHER rotating. Seriously.

                  The secret sauce is... telling the server the actor has rotated!

                  How did I get here?
                  First off, I had learned that you can't replicate functions in Blueprints. Only variables and Events. With that in mind, I set off trying a bunch of stuff.

                  What didn't work (Don't do this!)
                  My first attempt was pretty poor and didn't work... kinda... Yeah kinda didn't work. That means it didn't work but not entirely! What I had done was set up a Custom Event in my Pawn to send the pitch and yaw inputs from the PC to the Pawn. I was calling that event each Tick from the PC and sending the pitch and yaw as floats. Setting the event to Multicast only seemed to rotate each player locally (as expected, it warns to run it only on the server!), setting it to run on the Server was the opposite: I only saw my pawn rotate on the other clients! Progress, indeed.

                  Then, I decided I should have the server send the rotation back to the local pawn. I set up another event (LocalRotate) and set it to OwningClient. This ran after each time the previous event finished and simply took the rotation of the pawn and sent it back to the client. IT WORKED!! But this was complicated AND the Pawn was rotating like it was ratcheted. This is an effect of compressing rotators for net play in UE. It's something very common for games to do as it's purely cosmetic and can take up a LOT of bandwidth.

                  Here's how to NOT do it. Again DON'T DO IT THIS WAY (Even tho it kinda works, but sucks)


                  And, how it looks in motion:


                  (How to do it right in next post)

                  Comment


                    #10
                    How to ACTUALLY do it.
                    Rotate the PC

                    Rotate the Pawn based on the PC's rotation

                    Each Tick, send the server the pawn's rotation.


                    And, how it looks:

                    Smoooooth!

                    Next up: Movement!
                    Actually, sleep as the 2-year old is sick and will be screaming at me all night At-Least I figured out some replication in Blueprints today!

                    Source Files:
                    DOWNLOAD HERE
                    Last edited by Tom Shannon; 02-02-2018, 04:28 PM. Reason: Updated links to files

                    Comment


                      #11
                      great tread! good luck with your development.

                      Comment


                        #12
                        Good work! At last somebody's talking about replication ,that's why I abandoned my project in UDK!

                        Comment


                          #13
                          Nice thread, but I wonder is it even necessary to update rotation on every tick?
                          I was also checking the spawning and sync movement as well, guess if I found something( I want to have a volume to spawn players in instead of fixed playerStart locations.)

                          What I think is(since I haven't figure out how to do the random spawning part), when your input updates the Pawn, in Pawn blueprint where it sets rotation, make the rotation change replicatable by setting Replicate/ReplicateNotify(which creates an function).
                          And in the Pawn Blueprint defaults->Replication, there should already have a "Replicate movement", and this should replicate all update regarding transforms of a pawn.
                          Unreal Engine 4 Game Framework diagram for relation of all major base object types
                          Unreal Engine 4 Input Event diagram, scroll down to section Input Processing Procedural
                          Resident Evil Classic Camera
                          RPCs official document, Must Read
                          Everything you should know about replication

                          Comment


                            #14
                            Originally posted by PenguinTD View Post
                            Nice thread, but I wonder is it even necessary to update rotation on every tick?
                            I was also checking the spawning and sync movement as well, guess if I found something( I want to have a volume to spawn players in instead of fixed playerStart locations.)

                            What I think is(since I haven't figure out how to do the random spawning part), when your input updates the Pawn, in Pawn blueprint where it sets rotation, make the rotation change replicatable by setting Replicate/ReplicateNotify(which creates an function).
                            And in the Pawn Blueprint defaults->Replication, there should already have a "Replicate movement", and this should replicate all update regarding transforms of a pawn.
                            I thought the same thing about replicating the movement! But it simply doesn't. Atleast not the rotation. Funny thing is, if you disable that checkbox, this method doesn't work.
                            As far as updating every tick being intensive, yeah I could probably put some sort of check in and only update if there's actually been a change in rotation. I might give the repnotify a chance, it's possible way of doing that check easily.

                            As for the random spawn, I might go about it by making a blueprint with a volume and having it create X number of PlayerStart actors in the construction script by sending random line traces down, etc. that way you could visualize the possible start locations. Then, rather than sequentially finding a start location, you could get a random int.

                            Thanks for the input!

                            Comment


                              #15
                              I've played around your level, and come to conclusion that Pawn and DefaultPawn are classes that does not handle those replication check boxes.
                              If you switch BP_MP_Pawn's parent class to character, the movement would replicate properly without any additional event to drive update.
                              I think player controller is for when you have something extra, like the mini game example in Input examples.
                              (And this would somehow break your script, maybe some graph needs to be recompiled.)
                              Edit: by break I mean I can only see one arrow spawned in client 1 window. But when still using your input script,
                              I can turn client4 with mouse that sees movement from client 1(also its arrow). all other 3 clients stucked at their location, no arrow to be seen.
                              I use gamepad to control client1, and somehow keyboard and mouse assigned to client4 on start play.

                              Also, I think we both misunderstand what PlayerController class is about.
                              If you check the input example from ContentExamples, you will see that the player controller class has nothing in its graph.
                              In the UFO Pawn, it uses GetInputAxisMoveForward/Right/Up for movement and GetInputAxisLookUp/Turn for pitch and yaw.
                              Which use the input to drive velocity, and drive camera where and align pawn rotation to camera's view direction.
                              Third person obviously use a lerp and velocity direction to drive actor's direction.

                              I think if we ever need to build a multiplayer game based on just Pawn, Epic has to either make a insertable movement component that already handles replications,
                              or expose some class functions to allow us wiring them.(Have to check those source codes for sure.)
                              In the mean time, I think your approach plus some custom variable with RepNotify should get the ball rolling.
                              Last edited by PenguinTD; 04-06-2014, 10:09 PM.
                              Unreal Engine 4 Game Framework diagram for relation of all major base object types
                              Unreal Engine 4 Input Event diagram, scroll down to section Input Processing Procedural
                              Resident Evil Classic Camera
                              RPCs official document, Must Read
                              Everything you should know about replication

                              Comment

                              Working...
                              X