Unreal 5: How To Know When To Replicate

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys and today I'm gonna walk you through why sometimes when you um are trying to replicate yourself you actually don't need to replicate anything you can do some stuff locally but you just got to think about things um in terms of will this affect my gameplay is it required that this is a server RPC is it required that this property is replicated because the more properties that you have that are checked to replicate the more work the engine has to do and the less bandwidth there is going to be to go around to replicate things and make things not lag in your network games so I've made a little example today and it's a lure Factor okay and our widest example um is a good one I think is because I'm telling the server to start and stop this um actor for everyone but do not replicate the lurping because this is a lurpack that goes from point A to point B and it does a lerp and if you've never heard of a lerp I'll have a link in the description where you can learn all about them but this is a basic lurping setup so after five seconds it's gonna Force an update so everything after this will be forced to happen because this actor if I go to the replication settings in defaults if I can spell I've set it to have zero net update frequency is basically how many times the engine will check this property for um no check this object for properties that have changed and try to replicate them to everyone else so it's not checking this actor at all so you could even set it to dormant if you know about net dormancy but this is a this is something that you do for Network um server optimization anyway on from that after five seconds it's gonna set should lurp and all this is doing is setting a start and location which I get from getting the forward actor and timing it by a thousand if you know how vectors work and then add that to the current location um and then I go here everyone should say that this actor should tick because I'm setting it to True everyone and everyone should check this out to tick um that's because um I have disabled it by default to tick start with tick enabled so tick is disabled so this is Tick every actor has tick and you shouldn't really use tick very often but for some things it can work quite well and this is kind of an example where I think it can work quite well because it's a small alert from A to B it's not like it's going to be um very hard for the the um code to be processed it's probably it's a lot better if this was native if this was C plus plus it'd be a lot more efficient but hey ho so everyone's on tick is has an elapsed time which is less than duration of three seconds so every frame is going to come into here and it's going to lurp from the start position to the end position and this the alpha of that is divided by time elapsed and duration which is free and time elapse starts off at zero and duration starts off at three and every frame it adds time it adds the time elapsed the Delta seconds so how long it took between each frame and it adds that to the timer lapse variable um I do have a string here that sets a location and shows you the value of the locate the location but that's kind of spammy I'm going to leave it on for the um this example though so do be aware that there's going to be a lot of print strings on the on the screen anyway so this all this is is a cube that alerts from point A to point B and I'm going to talk about why it is in my opinion like a lot more efficient than you know um if you were doing this step as a server call um with like a has Authority check and setting the location just based off the server one this wouldn't work and two you're doing some more extra work on the um server so it requires more bandwidth I might as well just show you what happens so even the client can get on top of this lip doctor and we both smoothly get brought along no issues there's no jittering there's no nothing there's no disagreements between the server and client um maybe if there was some lag from one of the servers that maybe that it would get um it would end up with a little bit of a maybe it would Jitter along a little bit or something but using um Delta time is usually how people you know it can cause issues um if there's a lot of lag but typically people are playing games at 30 or 60 FPS and there's other things you can do to step in to try to make it a little better but the point being of today's episode is when do you need to replicate and when don't you you need to replicate some certain rpcs like if you want to tell it to start something like I've done here you want to tell it you know you should start lurping and you want to tell it when should it stop lurping and in this case it's when the elapsed time is no longer less than a duration and that will call a force an update and it should start lurping and you know what the really another key detail is which I went over is that the net update frequency is zero so you would think that this wouldn't um work over the network because it's not being updated well I told it I forced it off beginplay to start and then the client client machine can fill in the gaps all it needs to know is the start and end location and each client has the same duration if the duration was changing it would need to be done it need to be a replicated variable and it would need to be set on a server RPC if it was changing during the lurp but if you did that then you'd probably get some weird results anyway now I hope that example was helpful and if you have any questions leave them down in the comment section below and subscribe like if this helped and I'll see you in the next one have a good day
Info
Channel: Replicated
Views: 1,197
Rating: undefined out of 5
Keywords:
Id: T2JsvQxeFIc
Channel Id: undefined
Length: 6min 42sec (402 seconds)
Published: Tue Nov 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.