UE5: How to Eliminate Client Lag in Multiplayer Games with GAS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up DEV heads today we're going to talk  about a problem that I wish I knew when I first   started my multiplayer game as you can see  in the video when lag is introduced when the   client shoots there is a delay on the animation  if your game is a first person shooter or is   fast paced you're going to want to sit back  and relax and learn about local prediction   if you like Unreal Engine tutorials make sure  you like And subscribe for more Unreal Engine   videos first thing first let's start off by  creating a new Unreal Engine 5 we're going to   click on games then third person template and  then we're going to call it lag rep and hit create we're going to start off by  clicking on the BP third person character blueprint double click to open  it and dock it to expand it then   go to edit and project settings then  look for input on the left hand side and hit the plus sign from the action mappings  we're going to create our own by typing shoot gun then click on the Arrow to expand  it click on the keyboard and click on   the left Mouse button to buy it now that  we're done close the window and search up   shoot gun the input that you just created  then we're going to create a new custom event and call it server under score shoot after that we're going to create a second one  and call it multi-core shoot for the server   underscore shoot we're going to go to the detail  Tab and under replicates we're going to put run   on server and for multi-core shoot we're going  to select multicast for the input action we're   going to connect server shoot but make sure you  spell it wrong or else you won't find it in the list if you have questions or concern  or any other multiplayer issues make   sure you leave leave a comment below let's have a conversation when you create server  shoot make sure you drag it to the   Press arrow for Server under score  shoot we're going to drag it to multi- shoot and for multi- shoot we're going to add  the function of shooting for this example we're   going to just use a print string to represent  shooting but later on I will add an animation   in for the string I typed in I shot the gun  with a lot of exclamation marks I hooked it   up and then for the text color I changed it to  Green just to represent multicast I compile to   check for errors and then I hit play to test  it in game and as you can see every time we   click the eye shot the gun string comes out  on the upper left hand corner in green now   that that worked Let's test multiplayer  under number of players change it to two   and under net mode change it to play as listen  server when I test as a client everything works   as it should the shooting is broadcast for the  server and for the client now what we're going   to do next is to emulate lag and this is where  the problem lies go to advanced settings for network and then make sure to check  mark enable Network emulation under   emulation Target make sure you select  everyone and for incoming traffic make   sure you click bad this will rep % lag  I added more lag just to exaggerate the problem I increase all latency to 100 more  then I hit play to test again and as you can   see it's working because the client is loading  much slower you won't be able to tell in this   example but every time I click it takes about a  second to shoot so I closed out of the project   to show show you the P more clearly I created  another print string to show you a local action   and I connected it directly to the input action  without any RPC calls in the instring I typed in   instant shot with a lot of exclamation marks  now I change it to Yellow to represent local   prediction I clicked on play to test for the third  time and then I waited as a client to load in now   you can see the main problem are relying on RPC  calls to handle everything for you when you left   click you can instantly see instant shot string  popping up then a few moments later you can see   I shot the gun when you shoot it is not happening  instantly and this is where the problem lies for   most fast-paced games or firstperson Shooters  and if I spam this example more weird things   happen as you can see in the Sprint strings if  this scenario is still hard to understand what   I'm going to do next is use an animation as an  example this will give you a real life scenario   that you might do in your project so I went into  my epic game library and then I searched up for   pistol starter pack it is free to download on the  Unreal Engine Marketplace make sure you select it   and make sure you add it to your current project  and if you remember mine was called lag rep and   wait for the program to install it into your  project and voila a new folder appears in my   content folder pistol starter under animation  I click on fire and I look for the W1 sandf ire   single the next thing I'm going to do is retarget  this animation to my Unreal Engine TN character   by right clicking it and choosing retarget  animation assets then clicking duplicate and   retarget animation Assets in the ik section  I hit the drop- down and look for RTG UE man and for Target skeletal mesh I'm going to  look for skm Quint and then hit retarget we now   duplicate the animation with the proper skeletal  mesh so we're going to create a montage so we can   use it in our blueprint now that we're done go  back to your third person character blueprint   and create a play Montage note connected  and look for the new animation Montage we made don't forget to drag out your mesh  and connect it to the play Montage under   in skeletal mesh component I compiled and play  and as you can see as the server as there's no   latency everything works as it should every  time I click to shoot the animation Montage   plays instantly but now let's test the CLI as you  can see every time I shoot reprsented as yellow   it takes a while to get visual feedback and this  is a horrible experience for clients because lag   is being displayed especially those with high  pings and this will make your game feel very unresponsive I went back to the network settings and I  changed the packet loss percentage du two   because it was not even triggering when  I would click with packet loss I went   to hit play and you could clearly  see what I'm talking about in this example every time I shoot the client  takes a while to display its animation   to alleviate this problem you can simply  just add your animation Montage directly   to the input action with some modifications or  you can add gas into your project like I did   in this example what I did next is loaded in  a gas example part that I had ready for this tutorial and then open the BP main character and  then I clicked on the ability system component   on the left side and on the right side I  expanded granted abilities and I chose the   GSC gameplay ability for a quick example I hit  the Plus assigned to create a new one on the Fly and for this example I did the same thing and  I created a print string to represent shooting and   then I typed in shoot with a lot of exclamation  marks now that we're done with our ability we will   have to bind it to the input one key I could  have created a new input but for the sake of   time I just used number one I then checked out  the ability system component and put it into   the event graph I then searched up try activate  ability by class to trigger the new ability that   we just created in the ability to activate search  up the new ability name that you just created for   example ours is called New gameplay ability now  it's time to test and as you can see as a client   when I hit one it shoots instantly even gets  broadcast instantly but let's add some lag by   going to the Advance network settings and check  marking enable Network emulation same as before   for emulation Target hit everywhere and start  adding more lag than usual and I hit play to   test out the server first and as always the server  is always instant and as a client you can now see   that everything works instantly as well now the  reason why I showcase gas as another alternative   fix is because gas has endless of Tools in your  fingertips when it comes to replication local   prediction and client prediction if I go back to  my ability that I just created and then click on   the class default you can see I can execute dis  ability however I want and by default I can sh   the net execution policy to locally predicted or  local only or server initiated along with server   only this is one of the many features that gas  provides to make multiplayer developing much   easier if you like to reinvent the wheel You  by all means do not have to use this but from   experience I'm telling you gas really does help  you especially if you're new to game developing   and have a part time grasping multiplayer RPC  calls and whatnot I hope now you understand   about local prediction and how to use it in your  game in my case I had to redo my project several   times because I was not aware of local prediction  if you enjoy watching this video make sure you   like And subscribe and click on the video to  the right if you want to know more about ue5   tutorials if you love what you see make sure  you support me on patreon for more exclusive content
Info
Channel: DevGames3085
Views: 7,567
Rating: undefined out of 5
Keywords: game development, unreal engine 5 lag fix, ue4 multiplayer tutorial, ue4 multiplayer fps tutorial, local perdiction, ue5 local perdiction, multiplayer tips, multiplayer tips and tricks, gas, ue5 gas, multiplayer lag, client lag, server lag, how to fix client lag ue5, game development unreal engine 5, how to fix unreal engine 5 lag, client lag fix, animation lag ue5, how to retarget animations in ue5, how to retarget animation montages in ue5, ue5, ue4, ue5 client lag fix
Id: PTFrpcScPaU
Channel Id: undefined
Length: 10min 39sec (639 seconds)
Published: Mon Feb 19 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.