How To Make A Multiplayer Third Person Shooter - Unreal Engine 5 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys mizo frizzo here and I am very very excited to bring you what is my first replication tutorial so what we're going to be making here is a multiplayer third person shooter and as you can see here we've got several players with replicated vertical aim offset we've got particle effects and sounds we've even got blood Splat when we hit an enemy it's going to spawn blood Splats on the surface behind them and that is all replicated we've got damage we've got death and we've even got respawning so this character 5 seconds after they've died they're going to respawn at a random player start one of these four player starts in these boxes that are floating above the map and they can come in and start rejoining in the action like so now this is somewhat of a more advanced tutorial um I would call this intermediate rather than beginners because you will need some prior knowledge of blueprints and how they work um but that being said I have made this as easy to follow as I possibly could and I do believe that someone who's even only been using Unreal for say 3 days should be able to follow along and make this with me their very first multiplayer third person shooter I'm going to be explaining to you a few key aspects of replication such as handling data and where you want uh certain procedures to be executed such as executing line trace on the server so you can see here at the top left I've got my server and then these other three windows are clients and you'll see when one of these clients sence fires the line Trac is drawning drawing on the server there and nowhere else and that's because uh our clients don't actually need to know um where where the line Trace is being drawn they only need to know the hit so that they can spawn particle effects and stuff like that I'll also be talking to you about running certain checks such as is it a dedicated server in which case you won't need to spawn things like particle effects and sounds um is your player locally controlled so this character right here when it executes certain logic you don't want it to execute on everyone else's instance so you can see there's three other copies of this character and there's certain things that you would just not want to be executing on everyone's machine or on the server and only such as um setting this uh Crosshair and aiming down the SES you can see here that when I aim down the SES nothing changes on anyone else's game nor should it and so that's just another thing I'll be talking to you about it is I believe the best introduction to replication on the internet right now and it makes what let's be honest a lot of us want to make when we're first starting out in unreal is something cool something with line traces bright flash as loud noises gory blood Splats and multiplayer so without further Ado guys let me show you how to do this all righty guys so I'm going to create a new project using the third person template we are going to leave St a content and rracing unchecked and I'm just going to call this my tutorial project and hit create once the editor has fired up let's start looking at how to simulate uh multiplayer in our play in editor here so if I hit play here we've just got this single player Standalone uh game instance and what I'm going to do now is Click these three little dots up here and you'll see down here you've got some multiplayer options so I'm just going to change this to two and then in net mode I'm going to set this as play as listen server if I hit play now you'll see I've got two windows actually there's one other thing I'm going to do which is Select this new editor window for the play and editor right here so when I hit play it's going to create two new windows and you can see this one here says net mode server zero and this one says net mode client 1 so this is a listen server this is basically uh a player who's hosting the game so so this is the host right here and then if I press shift F1 to get my cursor back I can click in this other window and I can play as the first client right here and if I change this net mode to play as client what it does is it launches two windows again but this time you'll notice that they are both client client one and client 2 and now the server is running in the background so so we're not actually going to use this mode to test our functionality as we set it up we're going to use play as listen server just so that we can see what is being run on the server and what is being run on the client all righty so with that out of the way let's go ahead and set this up to play a bit more like a third person shooter so the first thing I'm going to do is open up the the unreal Marketplace and in the unreal Marketplace I'm going to find a few asset packs don't worry all of the asset packs are going to be free so the first one is going to be this animation starter pack you can hit add to project and if you can't see your project here you want to select show all projects select your project and then select the most recent compatible version for this asset pack which is probably going to be5 .2 but it's just going to be whatever's at the bottom the most recent compatible version and hit add to project and the next one we're going to find is military weapons Dark now this asset pack I've heard is not free everywhere for example in Australia I've heard reports of this not being free if this isn't available where you are I will give you an alternative option in a moment but ideally you'll get this one or military weapons silver I think it's called because these ones contain some nice animations with particle effects and sound effects that come along with it so you get quite a lot in these asset packs let's hit add to project and once again if you can't see your project here select show all projects select your project and then select the most recent compatible version and hit add to project if the military weapons pack isn't available for you then I suggest you look for this one it's called f PS weapon bundle it comes with some very nice skeletal meshes but these do not come animated and it does not come with particle effects or sound effects or anything like that so just FYI if you are having to use this one then any particle effects or sound effects or animations that we use when we set up this project you'll have to get those from somewhere else I just going to hit add project while I'm here and once again if your project doesn't show up select show all project select your project and select the most recent compatible version and add to project and the very last asset pack I want you to find is this realistic starter VFX pack volume 2 so find this one and hit add project and select your project and hit add project all righty with those asset packs added let's set this up to behave more like a third person shooter but first uh what I want to do is create a new folder and I'm going to start making some of these things my own such as the BP third person character so I'm going to go into content I'm going to right click and create a new folder I'll call it multiplayer if I can spell it correctly and within multiplayer I'll create a new folder and call it blueprints I will then grab from the third person and blueprints folder the BP third person character and drag it into my multiplayer and blueprints folder here and copy and then I'm going to go in there and I'm going to rename this bpor character uncore TPS for third person shooter like so I'm going to open this up and let's start making some Chang in here so it's more like a shooter um I am going to change the skeletal mesh asset to many and I'm going to change the enom class to ABP many you don't have to do it like that you can use Quinn and ABP Quinn if You' like um but I prefer to do it this way because we are going to be making changes to ABP many anyway because AP Quinn is a child of ABP many um I suggest you follow along just do as I do so the first thing thing we're going to do in here is search for y and we're going to check use controller rotation y we're also going to search Orient and uncheck Orient rotation to movement like so and we're also going to select the camera boom here let's change the target arm length to about 300 and let's let's change the socket offset on the Y and Z to 75 and 75 like so and now if we hit play like this um oh we're still using the default porn class yeah so let's not test just yet um I'm going to in the blueprints folder while we're here create a few core blueprints that we're going to use for multiplayer and the first one is a game mode so I'm going to right click and go blueprint class and you've got this game mode base here but what many people don't real realiz is that the game mode base is a sort of uh secondary one that was created for more single player use if you search for game mode you'll see game mode base here but then you'll see a chart of that called game mode and this is kind of the original one that was created uh back in the day when unreal was created you know to for unreal tournament for sort of online firstperson shooter games um so game mode is the one you want to use for multiplayer not game mode base game mode so I'm going to select game mode and hit select and I'm going to call this bpor GM for game mode uncore multiplayer and I'm going to contrl C multiplayer because I am also going to rightclick blueprint class and I am also going to search for game State and here as well you'll see game State base and game State and it is is the same again so game State base is made to work with game mode base and game state is made to work with um game mode so if you use game mode but then you select game modes a game State base it will break your game if you're using game mode you want to use Game state if you're using game mode base you want to use Game State base so we are going to select game State and hit select and I'm going to call this bpor GS for game State uncore multiplayer we're not actually going to do too much with these at the moment but these are just a good sort of core set of blueprints that you want to create uh and use for your multiplayer setup the next one we're going to create is a player state so you can right click go to blueprint class find player State create a player State and this will be BP underscore player State uncore multiplayer this is good for handling uh stuff such as a players score and whatnot stuff that you need to pass to other players and you know um we're not going to use all of these like I said but it's good to have um and one that we are going to use is a player controller now you really this is crucial to create your own player controller because the base player controller is does not really work for multiplayer um you kind of need to create one that is a child of player controller so it's still a player controller um but the base one is kind of the parent class and it it doesn't really work very well with multiplayer so you need to create your own so we'll call this bpor PC for player controller multiplayer like so and while we're here let's create also a widget blueprint and use a widget and we'll call it um wbp for widget blueprint multiplayer we're not going to do anything with this one in this tutorial but again it's good to have um so game State and player State and the widget we're not really going to use um but we're going to set these as our defaults anyway and where you can set these as your defaults is over here in World settings and game mode and selected game mode you've got its class defaults here so if you don't have this world settings uh tab you can find it in window and World settings right here um so I'm going to change this to my multiplayer BP game mode multiplayer and here you'll see we have the defaults right here you can set them here or you can also open up your game mode and then go to class defaults and over here you'll see them right here so in game State we can change our game state to our BP game State multiplayer player controller class will be our BP PC multiplayer and player State class will be our bpps multiplayer like so if I save that and I go back out you'll see that it's changed these right here so you can change these in the world settings right here uh you just need to make sure the game mode over ride has it selected and then um these class defaults will appear here we can also check in Project settings under maps and modes that the default game mode here is our bpgm multiplayer so we have that game mode override set on our third person map but um it's good to change it here if the project is going to be totally multiplayer change your default game mode to multiplayer that way if you change Maps or whatever you won't get confused as to why it starts acting weird because it might go revert back to the third person game mode um we also here in default porn class we want to set this To None because we're actually going to set this as part of our code um the yeah the reason for this is that if our player dies and then we destroy that actor the BP third person character is been destroyed and that was our default porn class like um yeah we don't want to get it from here we want to actually do it as part of our logic when we start up uh now that we've got all those created and these set we can hit save all and actually for now I am just going to leave the default porn class as BP third person character we will come back to this and clear it once we've set it in code okay and the reason I'm going to set that is just so that I can oh sorry not BP third person character uh BP character TPS the one that we copied and renamed right here so now that if I hit play I've got a bit of over theher action and my character rotates with the mouse and uh yeah that's a bit more like a third person shooter um let's create a sort of upper body pose and add a weapon to this character and to do that first we're going to have to retarget some animations from our anim starter pack so head over to your anim starter pack folder and inside of here let's create a new folder and call it uh ue5 just for ue5 retargeted animations and I'm going to filter these by animation sequence here so if you don't have these filters right here you just got to click this little icon and you can find animation and animation sequence and this will uh filter by animation sequence so we're only seeing animation sequences here and then I can press CR a to select all of them and right click retarget animation assets duplicate and retarget animation assets I'm going to select the retargeted ue4 menu to ue5 menu this comes with the third person template uh content pack so u4 to u5 manyu and I can change the directory here to my u5 folder that I've created and I can add a prefix if I like say UE 5core so that oops so that these all are uh prefixed with ue5 uncore and hit retarget uh make sure this is on the mesh that you're retargeting too so if you're using Manny select Manny if you're using Quinn select Quinn and hit retarget this may take a few seconds once these have all retargeted it should take you to the folder the directory that they were re uh duplicated and retargeted into and we are not going to make use of very many of these in this tutorial but this is just a good resource it gives you a bunch of animations to work with so if you wanted to add more weapons to your project and more functionality such as crouching and proning and whatnot um yeah this this will be very handy so the first thing I'm going to do is find hit react one there's a bunch of hit react animations here but I'm just going to use hit react one what I'm going to do is right click on it and go create create anom montage I'm going to leave that named as hit react 1 montage and open it up and you see we got a nice little hit reaction Montage here I'm going to go into the asset details here and I'm going to change the blend in time to 0.05 the blend out time to 0.05 and save that and close that that's all we need to do in there we need to create this animation Montage for later for when our character gets hit um the other thing we're going to do is find idle rifle iron SES where are you idle idle rifle iron sights right here I'm not going to open this up just yet but we're going to use this animation in a moment first we what we want to do is add a weapon to our characters skeleton so I'm going to find the skeleton which should be in characters mannequins meshes and SK mannequin right here I'm going to first change the preview mesh to whatever mesh I'm using so for me that's skm many I'm going to change it to skm many and then I'm going to select this apply to asset because this has only been set temporarily so now this asset has this preview mesh selected permanently I can select preview animation and I can find my idle rifle Iron Sites I can pause this animation and take it back to the first frame here and now I'm going to find the right hand I'm going to right click add a socket I'm just going to leave it named as hand R socket and on hand socket I'm going to right click and add a preview asset and it's going to be the assault rifle B from my military weapons Dark pack um if you're working with a different mesh you'll just have to adjust accordingly but the first thing I noticed with this assault rifle is is that it is massive so what I'm going to do is change the relative scale on the socket here so that I don't have to change it anywhere else anywhere this weapon is spawned and attached to this socket it will take on this relative scale um by default that's the default setting um I'm now going to adjust this socket uh sort of location and rotation but I'm only going to worry about how it sits in the right hand right here I'm not going to worry about the angle or anything like that I am just basically going to sit it in the right hand like so maybe switch off rotation snapping and grid snapping and rotate it a little bit and that'll do we're making a third person shooter here so it doesn't have to be exact I'm not even going to worry about the index finger or anything like that uh when I adjust this animation I am just going to make it basically so it's set sat in the right hand like so and then I'm going to save this and close this and then I'm going to find that animation idle rifle iron sights I could just search for it but I'm stubborn um I'll search for it idle rifle iron s sites right here can open this up now that we've added that preview mesh you can see it's added to this animation I can pause this animation and take it to the first frame here and I am just going to adjust this pose a little bit and then I'm going to use this pose um as the upper body animation for my character so the first thing I'm going to do is go to the skeleton tree and find the right hand and I'm going to change this to uh World space right here instead of object space and I'm going to basically just straighten this up a little bit like so level it out a little bit and once this is level and straight and I can use the plane that the character's standing on there in the preview as a bit of a reference that looks about level there once that's been set I'm going to key frame the right hand here and then I'm going to find the left upper arm and just adjust it slightly so he's holding the weapon like so doesn't have to be perfect for the purposes of this tutorial that's absolutely fine like that and I'm also going to key frame that left upper arm if you made a bunch of changes here to a bunch of different bones you could just set them all how you want them and then over here you could press crl a to select the whole skeleton tree and then key frame everything in the skeleton tree if you like but I just changed the right hand and then key framed it Chang the left upper arm and then key framed it and now what I'm going to do with this paused on this first frame is up here click create asset create animation from the current pose and I'm just going to save this in the content folder and leave it called SK Manakin sequence um you can name it what you like you can be a bit more organized if you like but I am just going to save it in the content folder here SK mannequin sequence and you can see if I open that up even if I hit play you can see it's just a single frame animation so it's basically just a pose and that's fine for what we need here we're just going to use it like that so can close that and the next thing I am going to do is um open up my character and I'll just add the weapon here so in the components tab over here I'm going to add a skeletal mesh call it weapon I'm going to drag it onto the mesh so it's parented to the mesh and then over here I'm going to select the skeletal mesh asset as my assault rifle B and then the parent socket I'm going to set to the hand R socket that we created zero out the location and the rotation here and now he's got the weapon in his hand all right let's make this so that his upper body is sort of doing that aim pose um what we can do now is go to the enom class the enom class here ABP many c i can browse to that now if you've got this set as ABP Quin as I mentioned earlier ABP Quinn is a child of ABP many so everything that we do we want to do inside of ABP many okay so open up ABP many and the very first thing I'm I'm going to do is fix up this cast right here so it's casting directly to our character this is just casting to the character class and it's getting the owning actor um as object reference but we are going to delete this cast a character and instead we're going to cast to our uh what did we call it TPS BP character TPS or whatever you called it so this is our character that we're making our own going to cast directly to that plug these in and then I'm also going to change this set node to the character that we copied and renamed object reference so an object reference to my character TPS like so and click change variable type and now this is a direct reference to uh our character that we're using here okay the next thing we can do is go over to the atom graph and I am going to disconnect right here so alt click this pin to disconnect this I'm also going to disconnect this move this down here and off of Main States here I'm going to find a layered blend per bone plug this default slot in here plug this one in here and then with layered blend per bone selected up here in the layer setup I'm going to drop this down and add a new Branch filter and I'm going to drop down that index and I'm going to make the bone name spinecor 01 and I'm going to check mesh space rotation blend and mesh space scale blend like so now what we can do is grab that animation that we created which for me is just SK mannequin sequence just going to grab that plug it in here hit compile and like so as you you can see here we've now got this animation on our upper body so if we hit play now our character's got a weapon and he can run and jump and whatnot with his lower body and his upper body is just aiming that weapon but we cannot look up and down so what we're going to do now is use our control rotation our Mouse input to rotate the spine bones of this character in a way that is replicated for multiplayer okay so usually I'll show you the way that I usually do it for a uh a non multiplayer setup and the way that I do it is in the event graph here I'll add a pin I'll grab my character reference from the variables over here grab my character reference get control rotation I'll split this struct pin and then on the pitch here the first thing I'm going to do is subtract this off of 360 so 360 minus the Y I'm also going to negate it so multiply it by -1 and I'm also going to check if it's greater than 180° and I'm going to use this check as a condition for a select float plug this one into a plug this one into B and this return value I can divide by the number of bones that I'm going to rotate so I'm going to divide it by five because I'm going to apply this to five spine bones and then I am going to make a rotator make Rotator leave that plugged into the X because this is actually the access we need to apply this to and then I can promote that to a variable and I can just call it pitch Rotator something like that I can plug this into the last execution pin here and actually what I'm going to do right now is select all of these and right click and collapse nodes and I can just call this calculate pitch rotation something like that okay whoops and now that we've done that we've got this pitch that's uh set off of the control rotation of our controller uh we can use this to rotate the spine bone so head over to the anom graph here and I'm going to grab these and move them way out to the left here I'm going to right click here and type mod search for transform modify bone I'm going to select this node and then translation here I'm going to uncheck expose as pin we don't need translation I'm going to leave rotation exposed as a pin but I'm going to change rotation mode to add to existing and scale we can unexp that as a pin and Alpha we can unexp that as a pin so you've just got this one pin rotation and the rotation mode is set to add to existing I can plug this one in here and I'm going to duplicate it four times so that we have five of them plug them all in like so grab our pitch Rotator and plug it into the rotation pin on all of these nodes and then the last thing we need to do here is select the bone to modify so on the first one I'm going to make it spine one on the second one I'm going to make it spine two third one going to make it spine three fourth one spine four and spine five now that's it that's this set up but if I hit play now you'll see that um this character oh it's replicating huh that should oh that's the server sorry it's replicating on the server but if I select the server um you'll see that it's not replicating this character in that window on the left is looking up and down but in the window on the right you can see he's not doing doing it so that's not what we want we want it to act more like this so see he's looking up and down in his own window there and in the left window he's also looking up and down you might see some like excis style blurring there um I do believe that's just a level of detail thing it doesn't really happen when you're nice and close but uh yeah it's a little bit glitchy sometimes um how we want to set this up to replicate is going to be our first little exercise in replication so in my animation blueprint here where we calculate the pitch we're getting this control rotation here but control rotation isn't replicated by default um it's just not part of the way that unreal uh replicates movement it has its own little framework to replicate movement in an efficient and reliable way um that does you know doesn't require too much bandwidth and this kind of thing thing just isn't included so we need to set this up ourselves we're going to do that in our characters blueprint and in the event graph and we're going to do it here on the camera input the first thing we need to do is create a couple of custom events so I'm going to create one custom event and I'm going to call it R for run on server underscore set pitch I'm just going to contrl C set pitch so I don't have to type it over and over again because I going to create another custom event and I'm going to call it MC for multicast underscore set pitch and run on server set pitch I am going to over here in the details panel select replicates as run on server and reliable and that turns this into what is called a remote procedure call or an RPC so this is calling to to execute on the server this is also going to be an RPC but it's going to be a multicast RPC so over here in replicates I'm going to select multicast and I'm also going to uh select reliable and what we're going to do is call run on server set pitch every time that we move the mouse here so I'm going to call set pitch run on server here and then on the server I'm going to call my multicast set pitch like so and then set pitch here is where we're actually going to set the pitch um so I'm going to create a variable call it pitch change it to a float we're going to set it here on this multicast and then I'm going to grab this pin and plug it into the uh custom event here so that it creates this input where we call the custom event I'm going to do the same thing again plug it in here so that over here now we have this pin and what we can do is get control rotation right click and split the structor pin and plug the Y into pitch here so we're calling run on server set pitch we're passing through our y control rotation our camera rotation basically and we're passing it through to run on the server set pitch multicast pass it through again and then here in the multicast event we're setting it and the last thing we need to do here is select the pitch and change its replication to replicated so you can see you've got these two little dots here signifying that this variable is replicated and now what what we need to do is go back to our animation blueprint and here in the calculate pitch function what we can do uh we actually have to pass that over so we have to go back to the event graph first and I'm actually going to add a pin I'm going to control and click and drag this down to the next pin so it happens afterwards I'm going to grab my character reference here off of character I'm going to get pitch and then pitch I'm going to promote to a variable within my animation blueprint I'll leave it called pitch and I'm going to plug this into that execution pin right before my calculate rotation um calculate pitch rotation function right there so now we're passing that pitch variable over to our animation blueprint setting our animation blueprints own pitch variable based off of it and and then in our calculate pitch rotation what we can do is off of character here uh sorry no we won't uh oh we don't actually need to set it within the animation blueprint we could just get it here and then set it from that um but we've done it now so I'm going to get my pitch and I'm going to hold control and click and drag these onto pitch like so and that is all we need to do in here now if I hit play and I'm playing as the client it should be replicated on the server like so and if I'm playing as the server it is also replicated on the client so this is going to work for all of your players now we now have um a nice third-person shooter setup bit of over the shoulder action and we have a weapon and a pose and we have a basically procedural vertical aim offset setup here so this is as opposed to an aim offset which is more of an animation setup um and it is replicated okay let's move on all righty guys the next thing I want to do is add a bit of aim down the SES Zoom when we hit the right Mouse button uh so we're going to be working in our characters blueprints event GR um actually I'm just going to extend this camera input to include our little uh server rpcs here to set the pitch and I'm also going to change the um cast here to our specific player controler that we've created so we can delete this cast to play player controller and instead we're going to cast to our BP PC multiplayer here um we can and plug this in here make sure that you plug this in and also while I'm here I'm going to promote this to a variable um I'll just leave it called as bppc multiplayer and I'm also going to add a check here which is kind of good practice um I'm going to check is locally controlled so I can right click here and find is locally controlled and put a branch now this doesn't matter too much with all of this stuff here because actually a controller is uh sort of always locally controlled if that makes any sense um clients don't don't have an instance of a controller of another client or of the server on theirs the controller only exists on the client and also on the server um we're just going to put this here in case we do anything else off of the end here that we don't want um we don't want executing more than once so on each if I set this to say four players right and I'm just going to duplicate this four times so that we've got four player starts here if I hit play now and we've got client one that's the server server client one client 2 and client 3 now each one of these is a different is a is its own instance of the game world so each one of these is a copy each one has four characters in it so we actually have 16 characters here in total okay um and when we do something on event begin play um let's say say when client 3 here joins the match they spawn in uh they spawn the world and they also spawn these other three characters um so these will spawn in and anything on event begin play when each one of these is spawned in will be executed unless we put in that check is locally controlled so we're going to put in a few checks as we go along um and this is what of them is locally controlled if we put a print string at the start here for example you will see it print uh when we've got four players you'll see it print 16 times if we put it at the end here it will only print four times because this stuff is only executing um sort of on the controller which is just one One controller per client if that makes any sense um another thing I'm going to do here is I'm going to move Mo all this out just a little bit and I'm going to put here a delay until next tick while we're here and the reason for that is when we spawn our um we're going to spawn our players through our game mode uh shortly and when we do that and we spawn the player and then we give a controller possession of that character um we we don't want this stuff to execute uh right away because there won't be a controller yet and it won't it won't add the mapping context you won't have control of that porn so we just put a delay until next tick here okay so let's do some aim down the SES Zoom so I'm just going to find some empty space and I'm going to right click and find the right Mouse button and I'm just going to set this off of the right Mouse button here you should be doing enhanced inputs for any any inputs but I'm not going to be doing that in this tutorial I'm just going to set this on right Mouse buttons kind of quick and hacky way of setting this up um and what we're going to do first on the right Mouse button is grab our character movement here and off of character Movement we can set max walk speed I can duplicate that plug in the character movement as the target plug this one into pressed and the other one into released and when we press it we want this to set to something like 150 and I'm going to click on character movement and check what the default Max walk speed is and it's 500 I'm going to set it back to 500 upon release like so um I'm also going to grab my camera boom here and I am going to set the socket offset set socket offset duplicate this down here plug in the Target and I'm also going to get the socket offset and I'm just going to set the socket offset as what it is at the time and we're going to use this when we press or release the right Mouse button and we move the socket offset using a timeline this will be our start point so we'll do that and then off of each of these I'm going to make a sequence with just two pins like so and off of then one I'm going to add a timeline I'm just going to leave it called timeline doesn't really matter um I'm actually going to put this on play from start and I'm going to double click on that timeline and then click add float track I'm going to make the length of that flow track say a quarter of a second 0.25 and I'm going to hold shift and click twice on the graph here to add two uh key frames you can also right click and add key to curve flator 0 I'm going to select the first key and change the time to zero and the value to zero and I am going to select the second one and I'm going to change the time to my Max maximum of the length of this float track which is 0.25 and the value to one then I can click these icons to fit to screen and if you want to smooth this out you could right click and click on auto like so give it a nice smooth curve um that's all we need to do in here we can close that um and that float track is going to be our Alpha for a lurp node I'm actually going to duplicate this and this is also going to plug into to play from start and on zero here I am going to stop the other timeline and the same on zero here I'm going to stop the other timeline so when we click the right Mouse button if it was already executing a timeline first it's going to stop that one and then start the other one like so and on update here we are going to set the socket offset um so we can grab our camera boom and socket offset and duplicate that over here um I can right click on this and split the struct pin and I am going to duplicate that and then I am going to find a lurp node lurp do we need to find float or is it just lurp I think it's just lurp um so we're going to lurp between A and B the float track here is going to be the Alpha and a is going to be the socket offset X like so and we can also grab the camera boom over here and set socket offset going to duplicate that down here plug these into update like so and make sure camera boom is plugged into the target there as well and we can split the struct pin on this offset and I'm going to plug this one into the X like so and I'm going to make this something like 100 so it's going to move 1 meter forward the camera is going to move 1 meter forward when we click the right Mouse button we also want to make sure that these other figures here stay the same so we're going to set those as what our default is on the camera boom so you can select the camera boom check what you set these as here the socket offset and remember we set it to 75 and 75 so this is going to be 75 and 75 and the same down here 75 and 75 and we are also going to grab this Alpha node duplicate it down here sorry lurp node and plug the float track into the alpha and this time the current offset is going to be a it's going to lurp from the current offset X down back down to zero and the return value plug into the offset X here so that should be working if we compile and save and hit play we can now zoom and zooms back out I actually might change that to 150 and make it a bit faster so I'm going to make this 150 and I'm going to go into my timeline here and I'm actually going to set this to 0.2 and the length to 0.2 just to make it a little bit snappier like so um and just to make this a bit quicker I'm just going to delete that one duplicate play from start plug zero into stop plug update into here and plug the track into Alpha like so now that should be a little bit snappier and zoom a little bit further and it does and nice okay so let's make now some simple firing logic uh so we're going to do a line Trace but what I want to get you thinking about with replication is uh where your code is going to be executed so this code for example is ex executed on our player because it does not matter to anyone else and a good test of that is you know you you possess this player click on this window and possess it and you do your zooming and nothing's changing on any anyone else's screens and nor should it right so this code we can um we can execute on the player and none of this needs to be replicated whatsoever um but if we are going to fire our gun what does need to be replicated does the line Trace itself need to be replicated um I would say no uh but also I don't want my players to be able to hack and cheat and draw Their Own Line traces or set their own health or own score or their own KD or anything like that all that sort of stuff will want to be executed on the server so um I'm going to right click here and find the left Mouse button and I'm going to use this to fire but I'm not actually going to do very much on um on on my player's blueprint itself I'm not going to let the player execute the line Trace I'm going to execute it on the server so let's right click and find custom event add a custom event and I'm going to to call it run on server fire okay I'm going to click on that and I'm going to change it to run on server and reliable um not everything has to be reliable for example like spawning particle effects and sounds and stuff doesn't necessarily have to be reliable but um for the purposes of this tutorial pretty much everything we're just going to set as reliable we want it all to to be guaranteed to to happen so when we press the left Mouse button we are going to call run on server fire call this remote procedure and here is where we're going to um set our line trace and a good tip here is that if it's something that you want to run on the server and you only want it to be you want to run a check that whatever's running it has the authority to run it then you can find a has Authority switch switch has Authority and then if it has the authority it will execute and if it's something remote it will execute something else maybe so we're going to execute everything off of this Authority pin right here now we're going to draw the line Trace from a socket on the weapon you do not have to set up your line trace this way you can set it up whichever way you like but I am going to draw it from a socket on my weapon so I'm going to find in my military web dark and weapons I'm using this assault rifle B I'm going to open up the assault rifle B skeleton and I will see that it has this muzzle flash socket here all ready for spawning the muzzle flashes and that's perfect for drawing my line Trace it's even orientated correctly with the xaxis pointing right at the front of the weapon so this will work very well indeed uh if you don't have a socket on your weapon for example if you're using the FPS weapon bundle you can right click on the rout you can add a socket you can call it whatever you like and then you can copy the socket name so I'm going to click on this muzzle flash and contrl C to copy the socket name just to make it foolproof so I don't um you know mess everything up with the typo and I can get my weapon here and get socket transform and in socket name paste my socket name like so and I want to pass this through to the server otherwise uh sometimes the rotation on the transform can break um so before I set this as a replicated variable I'm going to pass it through to my server so um I can actually just create the variable I can call it muzzle transform of type transform and set replication to replicated and I'm going to set that right here plug this pen into the custom event here so that it's called here on the call we got this input we can plug the return value into that input and now we have access to our muzzle transform on our server we can then do a line Trace by Channel and we can right click and split the struct pin the location will be the start point of our line trace and off rotation we can get forward Vector we can multiply the forward vector by a float single Precision I'm going to make this 15,000 which is 150 M and then I'm going to do the location Plus that forward Vector multiplied by big number and that's going to be our end point I'm also going to create a trace channel for this so I can go to settings project settings and search for trace and here you'll see Trace channels create a new Trace Channel just going to call it bullets and accept and I'm going to create another one while we're here and I'm going to call it decal for spawning the decals that we uh are going to add shortly so we've set this default response to block so we just need to make sure that things that we don't want to block it aren't blocking it are ignoring it so we're going to go into our characters blueprint here in the viewport just to make it easier to visualize you can select the capsule component and you can search for collision and here Collision presets you'll see that it is blocking bullets and we don't want our bullets to actually hit the capsule component we only want them to hit the skeletal mesh of the character so we can change Collision presets to custom and then select ignore bullets like so um we can then with still Collision searched we can select the mesh and collision presets here and we can just double check that that that is blocking bullets there as well uh while we're here what we might do is just increase the radius of the capsule component cuz it is Tiny uh let's just make it 65 something like that it's pretty chunky but that's fine all righty we go back to the event graph here we can change the trace channel to bullets we'll check Trace complex and we'll Change the draw debug time type to for duration um it's already got ignore self so we don't need to add self to actors to ignore that's already done for us very nice um okay so we can check that this is working now I'm just going to make these windows a bit bigger got a bit of split screen going on here I'm not going to fit them to the entire screen I'm just going to make make them like this so they pop up like this every time and I only have to do it once okay so if we select the server here and we fire you'll see that we've got a line Trace but it's not appearing on anyone else's screen because they don't need to know that information and that's what I want to get you thinking about is what does the server need to know what do the clients need to know now the server has this line trace and we're going to pass some information of that line Trace through to the clients for spawning stuff like particle effects and sounds the reason that you need to think about this stuff is that there is such a thing as bandwidth and you can't just pass everything to the server and pass it back um that's why something for example such as the dynamic destruction in the finals is so impressive because they're replicating basically simulated physics uh in a way that's really quite efficient r on a PS5 like no problem um so yeah that's why you need to think about um you know what's what's sent to the server and what's sent to the clients if I select one of these clients and I shoot you'll see there's a line trace on the server screen but not on anyone else's screen because that line Trace is just being drawn on the server and nowhere else so yeah that's a good demonstration of that and while we're on this topic I just want to show you one other thing which is that if I click these three little dots and change the net mode to play as client and hit play we now have four players and the server is in the background it's running in the background but if I fire now I'm getting a line Trace in all these windows but hang on you just told me that the line Trace is being run on the server and that the clients you know don't see that information uh this is just an editor preference so here if I go to advanced settings it'll open up editor preferences and level editor play and down here in multiplayer options you'll see something called show server debug drawing by default if I uncheck this and then I hit play it is now not showing those line traces but rest assured they are happening on the server in the background and you you can see that if I change the net mode back to players listen server and hit play and grab one of the clients you can see that's still drawing on the server and nowhere else nice okay so let's apply some damage and also spawn some particle effects and after that we will um we'll do some blood Splat decals spawned when when we hit another player it's a nice little effect so we want to give the players some feedback we want some loud noises and some bright flashes and whatnot um so what we can do is out of this out hit we can break hit result and usually you'll do a check here on the return value here do a check if we have hit anything but we're going to actually do that in our multicast instead because we are going to execute everything after this regardless of whether it hit um we we are just going to pass that through so what we're going to do is we're going to right click and create another custom event and we'll call it multicast uncore um spawn FX something like that I'm going to select that and I'm going to change it to multicast and reliable and I'm going to call it up here spawn FX multicast and I'm going to pass a few of the results from this hit here through um so the first thing I'm going to pass through is the hit um so I'm just going to bring this up here so it's easier to see I am going to add an input call it hit leave it as Boolean I am I'm going to create one more and call it hit location and that's going to be a vector I'm going to create another Vector it's going to be the hit normal so this is the uh normal of the surface it's it's hit we're going to use that to rotate the particle effects that we spawn the emitters and I'm also going to pass through the physical material so um physical material and that's going to be physical material object reference physical material object reference like so and this will be the return hit pass this through here hit location right here the normal not the impact normal the normal pass that through and pass through the physical material like so um and while we're at it let's set up the physical material so we can spawn a few different particle effects okay so we need to go into the project settings and search for surface and here you've got a bunch of custom surface types that you can create let's make one of them body for if we hit a player let's make one asphalt cuz we're going to spawn an asphalt particle effect but this is basically what we're just going to give to the blocks in the level um and let's also make one called metal just to have a another different one we can close this now and then what we need to do is let's create a folder we'll call it physical materials and in physical materials right click and go to physics and physical material and physical material select now I would normally call this fmat but the problem is if you have the engine content shown here there is some in the engine content called fsat uh default I believe and asphalt whatever um so I'm just going to call this pmore body okay I'm going to duplicate it and I'm going to call the next one PM asphalt and I'm going to duplicate it once more call this one PM metal I'm going to open up each one and change them to their corresponding surface type so PM asphalt open that up change the physical properties surface type to ashal save and close that and open up body change the surface type to body save and close that and metal change that to metal save and close that all righty now let's uh add some stuff to this spawn FX custom event the first thing I want to do here is do a check and this is another check that's important for how you handle uh data in your multiplayer is stuff like particle effects and sound effects and stuff like that we do not need to execute this on a dedicated server so if your game is using a dedicated server uh which is basically a machine that acts as a server and it doesn't have any player on it as opposed to a listen server where this listen server is actually a player and he's hosting the game so this guy right here is hosting the game and these other three players have joined but if you are using a dedicated server you don't need this stuff on here so what we can do is find is dedicated server and make a branch and now none of this stuff will execute if this is running on our dedicated server okay um the first thing we can do is grab our weapon here and play animation now if you have if you're using the FPS weapon bundle because you don't have access to military weap weapons Dark you won't have these animations you would need to find other animations or you can just spawn emitter at location and place sound at location and then use your excuse me use your muzzle transform to spawn those um those um emitters and sound effects at location um but I'm just going to play this animation fire rifle fire rifle W because this one if we browse to it got a nice particle effect and sound effect that goes with it very nice so now if we compile and save and hit play that's not actually playing why isn't that playing ah sorry this should be plugged into false uh that's my mistake there so obviously uh we only want this stuff to play if you're not on a dedicated server there's a bit of a brain fart there plugging that into true sorry about that this needs to be plugged into false so if we compile and save that and hit play yeah we're playing an animation and we can see it's playing from the server on all the clients yep so that animation is actually playing on the server and it's um playing for all of the clients cuz it's on on this multicast RPC so nice we've got a little firing animation and a line Trace being drawn on the server very good let's move on um the next thing we want to do is check if we actually hit anything on that line Trace so we can drag off of this hit and make a branch and none of this stuff we want to execute if we didn't actually hit anything um and we can now make a switch with our physical material here so we can drag off a physical material and do a switch uh oh we didn't plug in these inputs yet I'm sorry um oh we did um physical material physical material ah we need to get surface type sorry so off of physical material get surface type I often forget that bit this is the enumeration that's tied to the physical material so get surface type and then switch on E physical surface and now we've got default body ashfeld and metal um what we can do is let's start with ashfeld and we actually spawn ashfeld on default as well if we don't proc any of these other physical materials we'll also spawn the ashel one so on default here we can spawn emitter at location and here within military weapons Dark or no it'll be the uh starter VFX pack the star of VFS VFX pack so everyone should have this we can find this P asphalt and uh the location and the rotation will get from this hit point so the hit location will be the location like so and I'll get a reroute node and bring this just underneath these nodes here and the hit normal what we need to do off hit normal is rotation from X vector rotation from X vector and once again I'll get a reroute node and try and keep this neat and tidy and here off of this I can find a Delta Rotator and I'm going to change the Y by 90° so this is going to rotate our emitter 90° off of the just the way these emitters are lined um on the axis this means the uh particle effects will spawn out from the surface that you hit we can plug that return value into the rotation and the scale I happen to know that this particle effect is quite big so I'm actually going to make this 0.4 0.4 0.4 like so and everything else we can leave as default um but we can also play a sound at location so place sound at location the location will be the same location here pass this through like so and the sound that I'm going to set this as is called rifle impact Q rifle impact body que that's another good one rifle impact surface Q so if I browse to this one and hit play that's a nice little Ricochet sound that will do um and we also want to plug in asheld into the same one so if it hits either of these surface types this one is just none it will play this and before we forget I want to set um actually we'll do it after we set all this up we'll set up the surface Types on our characters and on the level um so the next one we can do is body what we can do is just duplicate these two nodes I'm going to plug body into here plug this into here and this into here might look a little bit confusing with these nodes actually I'll just pass this through like that okay and this one we can find blood Splat cone and make sure we plug in the rotation here and I'll leave the scale the same again very nice and then metal we can duplicate these plug this into metal plug in the location here and the location here and this one is going to be there's a nice little default just P default and it's just kind of more Sparks than um than the ashel one it's just Sparks so it's a good little effect to have on metal um and make sure we plug in the rotation as well nice now that we have these uh we can set up these surface types so that these different surface types proc when we when we hit stuff so the first one we can do is asheld and what I'm going to do is just select all of the cubes in the level here um so I might just manually do this I'm going to select everything that starts with SM here for static mesh and it's going to be all of this stuff in the map here and that should be everything oh we're missing these ones I think here we go nice ah we don't want these cubes actually they are not ashel um nice that is everything there and then here in the details panel we can find physical material override and we can change that to our pmore asheld like so nice and actually just as a test I'm going to select these cubes and I'm going to make make them metal So Physical material override change to PM metal and then for body what we need to do is change the physics asset on our character so here in characters mannequins and rigs you'll find this PA mannequin this is the physics asset that Manny is using and what we can do is click the pelvis here in the skeleton tree and then shift click the right foot so that we select all of these and we can physical material override here look for our PM body select PM body nice and uh let's test this but I'm going to leave this open because I'm also going to set this up to do a head shot um just before we set up our apply damage I'm going to set this up to also do a head shot but just before we do that let's do a quick test that on every client sorry I'm just going to turn the volume down so I can hear myself speak um every client has these particle effects spawning like so but the line Trace once again is only spawning on the server that's where it's being calculated nice that's working very well so the ashel one is spawning if we go over here that's like I said doing more of a spark a little bit hard to see there we go spark effect ashf effect and if we shoot another player it's kind of hard to see might just make this server one quite big and use it there we go got the blood Splat cone effect and it is spawning perpendicular to the normal as intended nice what we can do to to add a little bit of effect to this um blood Splat and hit is a uh add that little Montage that we created the uh hit react one Montage so where we want to actually execute that is um we want to do an apply damage node and then we want to multicast that um that animation montage to everyone so what we can do is head back to our character blueprint and back to our runon server fire here and we're going to add some more stuff to the end here uh we can straight up just apply damage and this is a very very Nifty node that can just apply damage straight to um straight to the porn that you've hit the actor that you've hit rather so we can plug hit actor here into damaged actor we can change the damage type here to just the default damage type um and we can get a reference to self for the damage causer not that we necessarily need that for what we're doing in this tutorial but event instigator and damage causer can both be damage causer no we can't uh plug self into event oh event instigator yeah never mind we don't need this um and for now I'm just going to change the base damage to 10 and then what we can do is a event any damage node so I'm just going to put this down here because we are going to add some more stuff to the end here um but this is everything that we're doing on the spawn effects we're not going to add any more to this so I'm just going to put this down here I'm just going to look for event any damage okay and now anytime damage is applied to a character this will fire off um but obviously um we want to run some things on the server and also cast them to the other clients so what we can do is create a custom event call it run on server uncore any damage I'm just going to contrl C this and create another custom event and call it multicast uncore any damage like so this one is going to be run on server and reliable this one is going to be multicast and reliable like so and here on event any damage I can call my run on server any damage and then here we're going to call the multicast any damage um but first we're just going to check has Authority so switch has Authority like so and this is where we're going to calculate the damage so the players health because like I said before to reduce opportunity for cheating and hacking we don't want to give a player opportunity to set their own health we want to do it on the server if we have authority um so we'll do that in a moment but first we're just going to call our multicast any damage and then here we're going to play our Montage on our mesh so grab our mesh play montage and it should just be the only Montage that we've created for that skeleton so hit react one montage and nice that should all be well and good so if we hit play and we shoot another player he's doing that little montage and if we get what I might actually do just for testing sake is move these player starts so that they're kind of facing each other if it says bad size it's probably just clipping through the floor so it's not good for spawning so you just want to drag it up a bit and press end if you press the End Key it will drop it down to the surface below so let's just put these like so so they're all kind of facing each other this is easy iier we can see more players um so if I shoot him he's doing that on yep on all clients he's doing his Montage on all clients it's all working as expected very nice okay very good so this is a good little test just to check that those um those remote procedure calls are calling correctly and replicating on all clients that is working well so now we have a nice little framework here for if any damage is caused to a player uh any damage node is called it's then running this remote procedure call on the server any damage and that remote procedure call on the server is running another remote procedure call to all clients like so this multicast so nice um let's go ahead and set up a very simple Health System and then um we can look at spawning the blood Splat decals and and maybe um headshot damage um and then we'll do respawning and spawning and starting the game mode and we'll all be finished um so let's just create a variable call it health and it will be of type float and if we compile we can now set the default value and let's set the default value to 150 something like that whatever you like um and then we're going to set the health here and what we're going to set it as is the health minus the damage can plug this in here and this minus we can plug into the runon server here and it will create this input we can select it and we can rename that input to damage and then you'll see damage pin input on the call here and we can just pass that damage from the event any damage over like so and it is as simple as that now I'm not going to make this health variable replicated because for the purposes of this tutorial of this game that I'm making I did not need the health to be replicated but if you did for example want to make some UI that showed the um you know the damage and the current health of enemy players when you shoot them then you would need to replicate this and you'd need to pass it through to the appropriate you know to the player state or whatever um but for the purposes of this we're just going to set it inside of each player like so and then after we call MC any damage what I'm going to do is check if the health is um less or equal to zero so less or equal to zero make a branch plug this in and if it is less or equal to zero I'm going to set a Boolean let's call this Boolean alive question mark compile and make alive default value true so by default we are alive and if we run out of Health we're going to set alive as false like so and then we're going to call a death event but just before I do that I am going to add a live as a condition on a branch at the front here because if our character isn't alive we don't want to run any of this code when we shoot a dead player we don't want it to do anything it's just going to be more information doesn't need to be run on the server so um we don't need to to change their health or anything like that or or play any montages on them so we'll put this check here nice and then what we can do is um just make a multicast event in the case of their death so we can right click find a custom event multicast uncore death we can select that we can make it a multicast reliable and we can call it here on the end multicast death like so and I'm going to demonstrate another problem with replication here which is the difficulty of um replicating simulated physics such as they do in the finals which I have my theories about how they've executed that so well but uh we'll save that for another day so you can play an animation on death and it's easily enough replicated because as long as the character is rotated in other players worlds is rotated you know the correct direction and it plays the animation and they've got no more input to move that character you know it will all replicate um but if we simulate physics it's another story so what I'm going to do is I'm going to get the mesh here and I'm going to set simulate physics whoops set simulate physics as true I am also going to off of the mesh here I am going to set physics blend weight as one and I'm also going to set Collision Ena as Collision enabled query and physics like so and this is basically all you need to do to ragd doll a character but while we're here I'm also going to grab the capsule component and I'm going to duplicate this set Collision enabled plug the uh capsule component into the Target and make it no Collision so we don't want to keep on uh cra ing into their um capsule component after that character is dead we just want to turn off the Collision um and we can also get player controller and disable input uh the target will be actually the player controller the sorry player controller will be player controller and the target will be self like so nice so so now we've got death set as 150 as standard and when it gets below zero it's going to trigger this multicast event which is uh ragd doing the character and actually I'm just going to change the apply damage I'm going to change this damage to 30 so that it takes five hits to to kill that enemy um just for testing so now if we hit play and just going to make these a bit bigger I thought they would stay the same size every time we fire it up but not the case uno momento PO for all and now when we shoot a character five times they're going to rag doll like so and if you look very closely you will see that um it will not necessarily rag all exactly the same on everyone's instance um it kind of has this time it's replicated very very closely um which is interesting it may be because I used the server to do it um and here again the replication looks very close so this is not actually doing me a a service here um it's replicating very very closely every time ah here we go perfect example this time it has not so you can see on this screen he's kind of fallen over to the right his his legs are pointing to the right and here down on client 2's instance his legs are pointing to the left and also on client one instance his legs are pointing to the left on the server they're pointing to the right and on client 3 they're pointing to the right and this doesn't really call cause too many problems especially for the purposes of what we're doing today but one thing I do want to demonstrate here is that uh where our line Trace is being drawn is on the server my server is actually Dead characters dead on the server so it's not going to do me any good um but what I can do is I can maybe get rid of this guy and hopefully he falls differently on someone's screen he hasn't really that's annoying um how is he Fallen how's he falling on other people's screens uh the simulated physics has replicated pretty well again so anyway I'm just going to describe to you what I wanted what I hoped to show you here which was that the line Trace as we discussed earlier is only being drawn on the server and and the particle effects are spawning based on where that line Trace is hitting so if the body is um not in the same place on different instances you may get the wrong particle effect because the hit location here is from the server but if the body for example if the body was somewhere else on this screen let's say that the body fell drastically different and the body fell right over here and this is the body here you could shoot here and you won't get the blood Splat particle effect you will just get the asphalt one you would have to shoot over here and then as you can see on the top left window there that's where the line Trace is being drawn you would see blood Splats coming out even though there's no body there so uh unfortunately I wasn't able to demonstrate that as well as I'd hoped um but hopefully I've explained it in a way that you understand there so you could use animation to get over this you could just use a death animation instead um but for the purposes of what we're doing today this little rag doll setup is absolutely fine so I hope I've described that in a way that uh helps you wrap your head around it I'm going to change the damage here on the appli damage back to 10 um and and let's set up some headshot damage while we're at it so we're going to need to do a switch here and apply a different amount of damage um or we can just pass this through to a different function and put a switch there because I'm I'm actually going to put some other stuff on the end here so let's find our physics asset and we're going to change the head here to a different physical material but first we need to set it up so we can go into our project settings and search for surface and I'm going to add one more here call it head close that and in our physical materials folder I can duplicate one of these call 1 pmore head open it up change the surface type to the correspond excuse me corresponding surface type head save that and close that and now with the head selected here I can change the physical material override to our PM head like so and then in our character what I might do is just collapse this to a function going to collapse this to a function and call it um I'm going to call it set applied damage for lack of a better name cuz I just want to distinguish this from the apply damage or anything I don't want to call it apply damage or event any damage or anything that's being used by something else so I'm just going to call it set applied damage and the Damage actor is one thing that we need to pass through and the other thing we need to pass through on an input is the physical material nice and that's already physical material from the last one that we created um if it isn't just search physical material and select object reference of physical material pass through physical material like so and then double click this to open it up and here what we can do of physical material is get surface type I remembered this time get surface type and switch on E physical surface and I'm just going to duplicate this make sure you plug in damaged actor very important otherwise it won't pass through plug in damaged actor and then body is going to go into one head is going to go into the other and then base damage on head let's make it let's make it 60 nice and high um you could make it 150 if you wanted to make a this game really really hard um and frustrating um but I'm going to make this 60 little bit forgiving so lots of body shots to kill someone just three headshots and we'll just double check that that's working three head shots to down someone I'll change to another player player that isn't dead quite a few body shots yep that's working you could do a print string to see what type of damage it's outputting but this is predictable this is exactly how we set it up seems to be working fine so we'll leave that as it is very nice now one thing here is that it's quite hard to aim because we don't have a Crosshair but um and we are aiming we are firing a line Trace from the barrel of the weapon um so Crosshair in the center of the screen won't cut it but a little bit later on we will add a Crosshair that um moves in real time to where this line Trace is pointing so we'll set that up a bit later so the game is a bit easier to play um for now let's go on and add a blood Splat decal and the reason I am doing this Blood Splat decal section of the tutorial is not only cuz it's a bit gruesome and a pretty cool effect to replicate in our little uh third person shooter multiplayer game but it's also because uh it teaches us uh a small lesson here about replicated actors so I'm going to go to quickel bridge here and I'm going to browse down to the decals and first one here should be blood and these are all blurred out or graphic content uh even though I've looked at them before so it's kind of hard for me to see which one I downloaded but I'm going to look for one called High Velocity here we go High Velocity blood spatter um there's a few of these that's a decent one as well but I'm going to get this one here cuz I've already downloaded it so you can download it in whatever quality you like I just downloaded mine in the highest quality and add that to your project now this is going to create this Mega scans folder and decals High Velocity blood spatter and you'll see this material right here we're going to need to make a few changes to this material um but first what I'm going to do is I'm just going to create it within this uh folder right here I'm going to create a blueprint class of type actor and I'm going to call it BP uncore blood Splat like so I'm just going to contrl C that blood Splat so I don't need to type that again open this up I'm going to add a component it's going to be a decal component and I'm going to call that blood Splat decal I'm going to drag it onto the scene route like so and over here in decal and decal material we can find our our high velocity blood spatter decal like so um I'm also going to change the scale on the X to 0.01 to make this nice and thin because we're going to spawn this directly on a Surface anyway and it doesn't need to be very wide at all and we don't want it bleeding onto other surfaces it creates this kind of whack looking effect so I'm going to make that 0.01 and I'm going to make this about 2/3 the size like so 0.65 0.65 um we might mess with this scale a little bit but that's all we really need to do in here except for in class settings class defaults we can search for rep and change replicates to true replicates to true so as I was saying uh there's a small lesson to be learned here and it's in this checking of replicates in the class defaults of this actor so this actor is now a replicated actor just like our characters and that means that any actor that spawned on the server that is replicated is going to be automatically spawned in everyone instance of the game I'm just going to close a few tabs here um so that's how this replication uh setting works now that it's checked if we spawn this on the server here it's going to spawn for everyone so if you for example spawned it here with your uh with your visual effects and your sound effects and whatnot it would spawn twice it would spawn once on the server and once everywhere else again so uh your your listen server your first player your host will just see it once and everyone else will see it twice which is not what we want we just want to spawn on the server here so the lesson here is that if it is an actor that you want to appear in everyone's game instance you would check replicates if it is not something you would want to appear for everyone for example a ghost image of a wall for a building system for something like that you would only want to cast that directly to the owning player so um that's how you control who sees What actors if it's an actor that everyone should see such as a rocket from a rocket launcher or a vehicle or something like that then you know that would that you would check replicate if it's something like a ghost wall for a building system or a phantom helper of a character that no one else can see or something like that then you would not check replicates you would just cast that directly to um the owning character so that only they see it um okay so with that in mind let's spawn our little blood spatter here um we're going to need another line Trace here and this logic here will get a little bit messy but just follow along and what we're going to do is draw another line trace on that decals channel that we created earlier and specifically for the purpose of uh spawning our little blood splatter decal so what we can do is after set applied damage here we can uh do another line Trace by Channel and the start point is going to be the hit location of our bullets line Trace like so so we're going to start it at the hit actor and it's going to draw from there and go on and we will change this to the decals Trace Channel and Trace complex and put draw debug type on for duration so we'll do that for now and the end location we will do the start location plus the forward Vector from our other line Trace Times by however far we want this to go so I'm going to grab from the forward Vector here and I'm going to multiply this right click and make this float single precision and I'm going to make this 1,000 for 10 m so the blood Splat will spray on any surface up up to 10 m behind what we hit and plug this in here and then this will be our end location like so very nice um we want to make a couple of conditions here so we're going to do the return value here make a branch see if we hit anything but I also want to check if the other Trace hit anything and if it didn't then don't do anything so we don't want any errors here so I'm going to make an End Boolean and I'm just going to grab the return value from this other Trac right here I'm going to try a little bit to keep this neat um what I can do is just delete that line actually make a reroute node here plug this in here reroute this over the top like so that'll do and I'll just pass this one down below here try and make everything as easy as possible to follow that'll be fine like that try to keep as few of these lines overlapping as possible and now that we've done that check what we also want to do is check that this first line Trace actually hit an enemy so we can grab this hit act uh sorry this physical material here and just in the spirit of keeping things neat I'm going to make a couple of reroute nodes like so and from here I can get surface type and I'll actually just leave that down there and switch on E physical surface and if both of these traces have hit something and that something is body or head then we want to spawn our blood Splat actor so off of body here spawn actor from class and also off of head the class is going to be our BP blood Splat BP blood Splat and stick with me here because we're going to do some more advanced stuff on this spawn transform just to make it do some cool stuff um but first let's just change this Collision handling override to always spawn or try to always spawn ignore collisions um it doesn't have Collision anyway so don't worry about that and off of Spawn transform we can make a transform and the location that we're going to spawn it at is the hit location from our blood Splat line Trace so we'll grab this out hit and we'll break hit result drop this down plug the location into the location here and also get the normal and rotation from X Vector like so and I am actually going to add some randomness to the rotation of our blood Splat so it's not just rotated the same way every time so what I can do here is get a Delta Rotator and then I can right click here and split the struct pin and we are going to grab the X here and a random float in range and our random float is going to be anywhere from 180° to POS 180 like so plug this into the rotation like so and let's also do something Nifty with the scale huh let's make it let's make our blood Splat larger the further away the surface is behind the hit actor if that makes any sense so I can right click on the scale here and split the struct pin and I'm just going to put this down here like so make a little bit more room by moving this damage and death stuff down cuz we're going to add some stuff right here and what we're going to do is the location of our blood Splat uh line Trace minus the location of our um bullets line Trace so this is basically this is the vector between the end of our gun and the um and the sorry this is this is the vector between the hit point that we've hit the enemy and the wall behind them so what we can do now is get the vector length of this Vector length and this is the distance uh between the enemy that we've hit and the wall behind them so we can use this as a multiplier um now we're going to need to make this really quite small uh what I might make it is 0.02 um and then we're going to multiply that just going to drag this onto the bottom one here and I'm going to plug this into I'm just going to plug it into we actually don't need to split this we can recombine it and I'm just going to plug that straight in there what do that converted it to double Precision float I wonder if we can actually just just right click here it's R because it's single Precision that's all right we can just plug that into scale like so and what we're going to multiply this by is another random float in range and this will again have to be quite small it depends what you set this as um but what I might set this as is uh 0.1 to 0.2 something like that nice now that might seem a little bit complicated but it's just a nice little feature to add so that when we hit an enemy um the further away the wall is behind them the bigger the blood Splat and it's going to have a nice little bit of random rotation added to it so if we hit play now we can shoot an enemy it's not actually spawning the blood Splat why is that I've done something wrong here body or head on the first physical material that we've hit both line tracers have hit something ah it'll be the um the decal line Trace is hitting the character so just make sure you go to the capsule component here search for collision and under Collision presets let's just ignore uh decals line trace and also ignore it on the character so select the mesh as well change the Collision presets to custom and just ignore decals make sure you do not ignore the bullet line trace or anything else the only thing you want to change here is the decals so we we're not actually going to spawn the decals on other players we're not going to Splat blood all over players and whatnot and that is working now so yeah sorry about that um and that's like a that's a nice amount for that distance and if it's a bit closer it'll just be a little blood Splat like so what I might do is just grab another client make it full screen um or video memory has been exhausted extremely poor performance um yeah so this might be hard to run on some of your machines but that's working quite nicely the only thing the only thing is that the this Blood Splat um doesn't look very red and has some strange artifacts going on so with this uh window open I'm going to shift F1 here I am just going to make it a little bit bigger and I'm also going to find my um my material instance here and open it up and might dock that here and this one over here and then I can fiddle with a couple of the settings in this material instance um opacity that's going to get rid of that window um that's actually quite annoying set opacity down a little bit hey that actually looks a lot better and color overlay let's just add some red so pump that up to about 08 maybe that looks a lot cooler yeah that's nice and red oh yeah that looks good you could fiddle with that a little bit more if you like but um that's good for me now just have a little play here and make sure that everything is replicating correctly got our particle effects got our blood Splats and is that replicating for everyone yes it is very nice very good okay let's move on and just before we set up our game mode for respawning and whatnot uh let's set up this map for a little bit of multiplayer um by putting some spawn points that are sort of floating above the map that we can run off and jump on into the map and fight and let's also add our Crosshair widget um that will show us where we're aiming so I'm going to grab the floor and three of these walls and I'm going to hold alt and shift and click and drag this up and then I'm going to press R for scale and let's just oh not that one not that one either let's scale these I'm trying I'm trying to do it the easy way here but uh that doesn't seem there is an easy way um maybe if I select all three no that's not working for me either okay I'm just going to do this the hard way each each one um so I'm going to scale this down and just make a kind of little platform that we can sort of run in and jump off of onto the map and this will be easier if uh grid snapping switched on so you might want to switch grid snapping on and put this one in here like so that's nice that's all I want and then I can select all of these and I'm going to put these kind of staggered so that uh it's harder for player to shoot each other player each player at their spawn no spawn camping in my game Over My Dead Body um and make sure rotation snapping is switched on rotate this around and this one I'm going to put over here like so and then I can select both of these and rotate and hold alt and rotate them 90° and then move these over like so and this map is not symmetrical so let's move that one in a bit and this one in a bit like so and that should do I just don't want the player to really be able to jump off the side of the map which they yeah they they probably could from there but they'll just die um they they don't want to die they want to win those ones are actually kind of further no let's move them away from the wall there so let's move this to about there this one to about there so to about here nice that'll do that way if uh players trying to trap another player in their spawn they've at least got some cover that they can use um all righty and let's just delete these player starts and I'm going to put one here so I can click here and Basics and player start and just drag that out here like so very nice I can hold shift and ALT and duplicate this one over to here rotate at 90° hold shift and ALT and duplicate it again rotate that one shift and ALT and player four can start right here nice nice now they all spawn in their own little if we try to jump off the map Ah that's going to be kind of hard and they wouldn't want to do it anyway switch on E physical surface ah so I actually should have checked where that where that error was and it's because we're not hitting anything ah yes um so on the set applied damage we want to check that we hit anything so we don't cause an error here um so what we can do is just pass that through as an input call it hit type Boolean and pass through the return value right here and then inser applied damage use that as the condition on a branch so that if we don't hit anything it doesn't execute that code nice very good okay um now that we've got that set up let's add a widget blueprint so what I'm going to do is in my multiplayer and blueprints multiplayer I might actually just multiplayer and create a new folder here and call it UI um and in UI I'm going to right click and import an image of a Crosshair if you don't have an image of a cross you can literally just Google image Crosshair and pick one from there one that doesn't have a background otherwise it will kind of be a block on your screen so I'm just going to right click here and hit import and right here I've got this Crosshair image right here which I'm going to import and then I am going to right click and create a blueprint class of type actor going to call it bpor Crosshair widget maybe open that up and add a widget call it Crosshair widget drag it onto the scene route and then over here in widget class I can find my ah I need to create a widget dop so I need to also right click and uh user interface widget blueprint and user widget call this widget blueprint uncore Crosshair open this up find a canvas panel drag it out also get an image and drag it out and with the image selected anchor that to the center zero out the position X and position y I'm going to make this size 50 and 50 make it uniform so that it's square and change the alignment to 0.5 and 0 0.5 so that that's right in the center like so and then appearance brush image and select my Crosshair Crosshair and there we've got a Crosshair right in the center of the canvas panel like so now I can compile save and close that and in my BP uh Crosshair I can select my Crosshair widget and change the widget class to the wbp Crosshair like so then we have our Crosshair and I'm going to change the space here to screen and this will disappear but that's okay uh we've just changed this so that it's always facing the player so it's in the screen space not the world space you can't see it here but it's just because it's facing the player so that's all I need to do in here I now need to spawn this and I need to set its location but you do not want to spawn this in your characters blueprint like you normally would in a single player game because this character is going to die and be destroyed and it's going to respawn as a new character another copy of this and it's going to create copy and copy and copy of that actor so we just want to create one and where we want to create it is in our controller so what we can do is find our controller blueprint which will be in our multiplayer folder where is it multiplayer Blueprints and we've got our player controller multiplayer right here we can open this up we're going to be doing a few things in here so I am going to open full blueprint editor I'm going to get rid of event tick we don't need that and on event begin play um is where we'll create this uh this uh widget blueprint um um or the blueprint actor that contains the widget blueprint to be more precise um and we're going to put another check in here which is a good a good thing to do for multiplayer we're going to check is uh local player controller and put a branch because if this is the copy of the controller that's on the server um and not controlled by the server we don't want it to execute this code we only want this for the local uh local player controller um so we can spawn actor from class here and set this as our BP Crosshair widget and just so this doesn't give us an error we can split the transform struct pit and now this is actually a set as a transform just set as 0000000000 z um so if we compile it won't give us an error uh off this return value here we can promote that to a variable we can call it Crosshair widget it's actually Crosshair blueprint but that will do um so we've created it here but we also need to set its location and the location that we need to set it as is where our Trace uh goes to so actually what we're going to do is right click up here and set a custom event and we'll just just call it set Crosshair location like so can't believe I didn't do any typos in that that's very impressive uh the very first thing we can do is get our Crosshair widget here and right click and convert to validated get because if this doesn't exist we don't actually want it to try and set the location uh which is going to be when for example our character is in the process of respawning um yeah the when when the character blueprint has been destroyed and hasn't been created and assigned this controller yet um so we need to pass through a couple of things from our character uh to be able to set this we can add an input we can call the first one hit it's just going to be our hit result Boolean we can create another one and it will be our um our hit location of type vector and one more Vector called Trace end because if we don't hit anything we're just going to move it to where the end of the trace is if that makes any sense um so we're going to pass this stuff through from our character and um we're actually going to do it on tick which is not very performant for a lot of things um but it should be fine for the purposes of just setting this tiny this tiny widget which is only going to be one copy of per player um and this is going to be set sort of on each um character each player's machine if that makes any sense because it's going to be executed by their controller which is in their instance it's not on the server um remember we put the check here um is local player controller so this is only going to be executed um on the local player controller which we can actually let's just put that check here as well like so okay so we're going to call this on tick in our characters blueprint so um I am actually going to use this Trace right here um so I can cop Cy I'm going to copy all of this stuff except for the muzzle transform I'm going to actually put it up the top here above event begin play and I'm going to get event tick and I'm going to do a couple of checks before I perform this line Trace just so that you know we can not perform it uh absolutely all the time so we can hold B and click to get a branch plug that into event tick and on the condition here I'm going to get an end Boolean and I'm going to check is locally controlled because we don't want this executing on players that aren't us if that makes any sense and we also want to check is not so not Boolean is not a dedicated server so is dedicated server we also don't want this you know executing on tick on the dedicated server this is very personalized UI this is just for each player um so we can plug this in here and I'm just going to grab the socket transform here that we set up on the left Mouse button to save me typing anything that I don't have to type I'm going to get that socket transform whoops whoops and I'm just going to move this stuff down here slot this in here nicely and I can right click here split the struct pin put the location into start and also into this addition node and put the rotation into this get forward Vector node like so and make this a little bit neater and that's all we need to do here we do want to draw it on the bullets Trace channel so that it it uh blocks on enemy meshes so the Crosshair lights up on the enemy mesh um and then what we want to do is check if the controller is valid so we've got this as BP PC multiplayer object reference to our controller that we created earlier we can get that we can right click convert to validated get plug this in here and then as BP PC multiplayer we are going to set the Crosshair location like so pass through the return value on the hit result right here pass through location on the hit results here and pass through Trace end like so and we can collapse this because that's all we need from that uh nice yeah that's all we need to do here so we can compile and save and head back to our player controller and now right here after is valid we can do our Branch for have we hit anything and off of crossair widget here we can set actor location we're going to set it off of both true and false and make sure you plug Crosshair widget into to the Target on both of these or you can put a reroute node like so plug that into both and if we have hit something then our hit location will be the location and if we haven't hit something then the trace end will be the location like so nice so that should work this guy's got a Crosshair very nice everyone's got a Crosshair like so nice there is something going on with the camera boom there when you move close to a wall it's sort of socket offset seems to be on a multiplier by that um and we can also we can see this line Trace being drawn on Tech for everyone and obviously we don't need to see that that's just for the spawning of our Crosshair but our Crosshair is spawning very nice got him all righty so let's uh turn off that line Trace draw debug type um so that's on tick here on tick change that that To None nice okay let's set up some spawning logic in our game mode um and some respawning logic when we die so what we can do in our game mode is set up a couple of functions so I don't know if you've still got the game mode open uh if you don't it'll be in your multiplayer blueprints folder bpgm multiplayer and open full blueprint editor here and we don't we're not actually going to do anything in the event graph here because we can just make these functions that we can call um and the first function I want to do is to find a random player start um now this is not going to be ideal for this setup where we've only got four spawn points and four players and you know we're kind of spawning in that little box but but it is a good little exercise to um just get a random player start you know you'd probably want to set this up um based on distance to the nearest player but that would be a little bit more complicated so what we're going to do in our game mode multiplayer is create a new function and I'm just going to call it um find random player start and in find random player start what we can do is find a very very handy little node called get all actors of class this returns an array of all of the actors you select here so we can select our player start and now this returns an array of all the player starts that are available um we can get the length of this array and it will tell us how many player starts there are and we can use that as a selector so if we get a copy here uh we can use that as a to select a random copy um so let's just get random integer in range right here and the minimum will be zero but what we want to do is just minus one of the length so subtract one and plug that into the maximum here because the length let's say we've got four player starts so the length is four but the index of this if I disconnect this you'll see the index starts at zero here so if the index starts at zero and we got four it's 0 1 2 3 so the length is four but the maximum index is three if that makes any sense so we're just going to make the length minus one is the max of this random integer right here um and here we can get get actor transform we can get a return node add return node plug this into the return node right here and plug the execution pin into the return node nice so now this will return a random uh transform of one of those four player Stars so we cre and we can click on this return node and rename this um player start transform or something like that player start transform nice um I can also make this a pure pure function so if I just select this here or you can select it down here and select pure this means it won't have any execution pins um it'll just purely return this this one one output uh nice we can create another function and we'll call it spawn player and spawn player is going to um basically we're going to do this from the controller so um we're going to call this from the controller on event begin play and also uh when our player dies we might have a little timer and then respawn um but basically so this is what I talked about in the beginning when I said we are going to change the default porn class To None because we actually want to set this in code and that's what we're going to do now so make sure that in your world settings or in your game mode here you change the default porn class to none so make sure that your game mode which we're in here here you can check the class defaults the default porn class is set to none okay this is just a better setup for multiplyer especially if you're going to spawn different characters um we'll set it here in the code instead so if you wanted to spawn different characters this is where you do it um this spawn player will need an input um and the input will be a player controller that will pass over if we if we call this function so add an input call it player controller player controller and it will be an object reference to a player controller so player controller object reference like so nice and what we can do is first get controlled porn get controlled porn and check is valid this is just checking if that charact if that controller is controlling a porn so if it is controlling a porn we'd first want to destroy that actor cuz we don't want copies oh we need to drag off of get controled por we can drag off of that and Destroy actor if they do have a character destroy it and if they don't we're going to just go ahead and create a new one so we can spawn actor from class and for now I am just going to set this as our um TPS our BP character TPS that we created and the spawn transform I am going to uh get find random player start here and we made this pure so this just returns a transform but I've had some ISS issues with this transform uh passing over the rotation so I am just going to try it this way I'm going to split both of these and plug these in like so and the scale can just be left as one that's fine um hopefully that works to fix my little rotation problem if we don't have a character if the controller isn't controlling character then we just want to go ahead and spawn that character blueprint like so and the last thing we need to do is possess it so we need to drag off of here and this might not show up so you might need to uncheck context sensitive and you'll find this possess under porn possess you're going to possess that porn and the target uh so this is the porn that's being possessed and the target is the player controller so we can pass that right across to there add a reroute node or two nice um and this is why if you recall we put a delay until next tick on our vent begin Play Because when this blueprint is created it will execute this stuff before this possessed node the next node in this um line of code gets executed so this will spawn the character and because this character has been spawned this stuff will execute and the problem is that this controller won't be given the enhanced input local player subsystem and the mapping context added to it um and the reference and so on and so forth so this will fail so if we just delay that by one tick and um that means that this will create boom boom and then the next tick this will have been possessed and the rest will fire off as expected nice so that should be everything here um let's call this on event begin play in our player controller so um and we'll have to we'll have to run that on the server I guess so in our player controller here on event begin play um we're going to check is local player controller that's spawning our widget we can just do that after so we'll do it in here um we will make a new custom event call it run on server score spawn player this will be run on server and most certainly reliable we'll also switch has Authority so check if we have authority and if we have authority we will cast to our multiplayer game mode BP game mode multiplayer and this will just be get game mode as our object and as the game mode we're going to spawn player call function spawn player and the player controller input that we created we can just pass over a reference to self like so and we'll need to to call this let's call this here so run on server spawn player like so nice um so we can check if this is working now because if it's working we should we should spawn this player when we start we've set the default porn class To None So when we hit start we should spawn at a random player start with this character if we don't then something is wrong and we have except for this guy I don't know what's happened there and these guys have spawned in the same box and that box is pretty tight um I don't actually know what has happened there with that fourth client oh it's worked that time I suspect it has something to do with the delay it seems to be reliably working um something just went wrong in the start there this can uh this can be kind of a feature in our game that you might spawn in the same box and you might have to you know take each other out or get out of there quick smart uh nice so the only other thing left to do really is respawn on death um so we can cast to our game mode and respawn when we die but we most certainly want to execute this on the server and the main reason is there's a very important lesson here only the server can interact with the game mode only the server can interact with the game mode so it has Authority on the game mode and no one else can set anything within the game mode um so we're going to execute this on the server um and it will be right here on death so we can get game mode sorry get game mode cast to our multiplayer game mode and as a multiplayer game mode spawn player and that should be all good to go we might put a delay in here of 5 Seconds and the player controller uh would need to pass through which we should be able to just pass through our BP PC multiplayer I hadn't thought about that to be honest but let's just try that out this guy dies after getting shot quite a few times and he should respawn after 5 seconds and he hasn't so yes there is a problem with how we pass through that multiplayer controller right there oh someone's respawned but it's not the correct player yeah this will this will probably work for the server because it's probably the player controller that we're passing through so what we might actually do is just pass that death event over to the player controller okay sorry about the confusion guys um all we need to do is in our player controller create a custom event uh call it player death and then off of that I'm going to make a delay of say 5 seconds and then call spawn player on the server like so and then that will call spawn player which will uh respawn the player which as you remember inside of that functionality we destroy the actor and we create another one possess it and then in our characters blueprint here on our run on server any damage at the end here where we call the death event what we can do is just get controller and we'll just C cast so cast to our BP multiplayer and then as our multiplayer player controller we'll call that player death like so nice and that should be all we need to do there if I hit play now and this the one time they've all spawned in different boxes nice um I can just shoot this guy across here so we can demonstrate kill this guy here see if we can get in at least one head shot and after 5 Seconds this guy will respawn at a random player start and he has respawned at the same player start as the host right here so he can light him up and this will be a good check to see if it also works on the hosting client the list server and once again he spawned in the same spot and gets his revenge nice guys that is it that is everything we set out to do I know it is a big one but I am very very proud of How It's come together um my very first replication tutorial if this video has been of any use or value to you whatsoever please hit like And subscribe if you haven't already and also please consider if you are so inclined making a small donation to the channel via the super thanks function within YouTube it goes a long way to helping me continue to bring you guys these videos and that's it thanks for watching and I will see you on the next one
Info
Channel: MizzoFrizzo
Views: 16,140
Rating: undefined out of 5
Keywords: how to make, your first game, first person shooter, third person shooter, replication, multiplayer, weapon system, movement shooter, third person shooter unreal engine 5, advanced blueprints
Id: FR81TqmZd-4
Channel Id: undefined
Length: 153min 33sec (9213 seconds)
Published: Thu Feb 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.