RepNotify Explained | Part 1 | Unreal Engine 5 Multiplayer/Replication Tutorial | Kekdot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign welcome guys to my new YouTube video so I decided to pick up the recordings again uh and to give you guys more YouTube videos so um in this video I want to talk to you guys about rap notify and how that works because uh I see a lot of people asking questions about multiplayer related stuff and especially wrap notify so I just want to clear how that works and give you guys some clear examples so what I got right here is the default third person project so I'm going to just show you an example of how you can use rapnotify and also why your app notify is useful compared to multitasking and stuff so to begin with we are here inside of the third person character we can simply click on play stand on one player and then hit the pi window and then we get ourselves our little window here [Music] [Applause] so what is a wrap node fly and how do you get it when it comes to multiplayer well the first thing that you have to do is that you have to get yourself a variable so just hit here and get yourself a variable and call this one uh dos something or whatever you want to call it it doesn't really matter compile and save and then if we head to the right here we will see replication options and then over here you see none replicated and wrapped notify so first of all let's drag this variable into the scene and get it and you can also obviously set it so this is just a variable well the first thing that you need to understand in order to make this variable replicate or wrap node file in this case is if you head over to class defaults make sure that whatever actor you're using this variable in is actually set to replicate so by default the character class is replicated and you can see that over here if you click on class default you see replicate is set to true and then when we click on our variable we see two options we see replicate and wrap node file so first of all when we set it to replicate we see this little icon appear here and what this means essentially is that the server each time when you are within the relevancy distance so the square distance of this is 150 meters by default I believe then this variable will basically communicate its value down to you as the client so if we have the server over here and the client over here which could be you or you are the server then the server will try to replicate it down so how this works is that you need to look at the variable as this and as this so basically we have a variable on the client here that contains a value right so in the case of a Boolean it's either false or true that's the value that this variable contains and then what you what what happens is that well this exists on the server and since the server is authoritative and knows everything and is always relevant and so that not cool distance doesn't even apply to the server the server is always up to date because you are the one that handles this replication and then the client here has the local variable value basically so if it is set to false then that's what you locally see and when you set this to be replicated then the server will try to send the data down from the server to the client and if this one is not in sync with whatever value the server has so let's say the server set to true but the client has the same variable still set to false then what replication does is that it will send that True Value down to the client and set it here to be true as well and it will do it at a certain amount of times and that depends on the server stick rate and of course that also depends on your network speed basically but over here we can see the net update frequency which is by default set 200 so it will try to do this as it says here a hundred times per second but that's a little bit cap because uh the server speed is not more than 60. so 60 FPS is to Max even if you have a computer with 500 FPS for example 60 is the max limit so unreal sets at 200 but that value will never be reached I don't know why they do it but you could for instance do like 30 and set your Square distance to something like 150 meters and then here you can also apply what is the minimum update frequency and with your priority you can basically change how important this variable is right or this actor in this case we we change the actor relevancy here and the actor update speed but anyways that's beside the point of this tutorial here um this will try to update UH 60 times per second in this case and then what is the wrap Note 5 because that's what this video is all about well if we then set this variable to wrap notify we will get a corresponding function that will execute when the value of this variable changes so for example if you want to have something happen when this goes from True to false then red node 5 becomes very useful because otherwise what's going to be your the other way to check this well you could have an event event timer like uh like this basically so you could have an event timer set to one second Loop and then every one second you could basically check the value right like has it changed if it has changed on my client for example then we want to execute some launch jig so when this goes from True to false you can check it like that or there's people obviously checking stuff like this on tick so on tick you could be checking if this value has changed from True to false but that's all pretty um uh well not so good and optimized so the real way to do this is to have that set to rep notify and when you do that you'll see that this change is to set with notify and you see that this unwrap function appears here now these functions unlike any other function so if I create my own function my own then you can actually put them in categories you can have pins and outputs these functions you can output them in any categories unfortunately and you cannot put any of those pins on it but this is the function that occurs when the data inside this variable changes so what does that mean well let's say that we have an event right custom event and it's a server event so let's say server uh change value then this would be a server event written on the server reliably then what we can do right now is if the server sets this variable it will automatically replicate the rep node file to the client and then both on the server and on all the connected clients it will execute this corresponding function and you can open this function by double clicking it here on the left or by double clicking the variable itself and then it will show you this function here so in this function we are going to do a simple print string that will say hello for let's say five seconds or whatever 10 seconds oh that's not then here you go so let's test this code I'm going to do keyboard o or P keyboard p and then I'm going to call my events server change value and I'm going to set it to true so when I set this to true then in the function it will say hello so let's go ahead and click here two players as a listen server hit play then we'll get one on the red left and one on the right on the left is our client here so if I now go ahead and click on P then you see that the client says hello and the server says hello and same here on the server if we press P we'll see the client say hello and the server say hello which basically indicates that this uh wrap Note 5 is not executed and then it executed this function here so why is this more useful than for example uh having a multicast so let's make a multicast if we do custom event multicast um change a value then we could check it like this so let's make this a multicast event reliable that set this variable back to just be replicated and then in when we press p on the server we're going to call our multi-cast event here and then the multicast event will set this replicated variable for us so if we connect all the wires then we can follow the logic here we press P the value comes true then we go to multicast and then we get the replicated variable which we can then print so let's click on play and then here on the left we're gonna press p and we'll see client one says true Service as true and then on the right client once has to serve as true but what is the big difference here well if a player is not connected during this event to your session so let's say you're hosting a multiplayer session and somebody connects five minutes after right and within those five minutes that that player was not in this session then this variable would have been set to well or let's say that an event would have fired here right so the print hello then that connecting player would miss this event it would miss the print hello event but in the case that you would execute you would put that logic back inside of this wrap notify variable here so if we would set this back to wrap Note 5 again then as soon as the client would connect even five minutes after they would get the variable updated to their local computer because the value would be different than their offline value and that would mean that they would still execute this event so this is useful for doors for example so if we would take a look at something like a door that is open and closed then this rap node file would be very useful to use there because even players that would not be connected in your session at that time would still get this update and execute this function and they would not miss an event so they would not see a door out of sync in that case well guys I hope that makes sense that's it for this video I'll be making more of these random videos just explaining multiplayer topics so if you like and enjoyed this video then please leave a like And subscribe to the channel alright bye guys [Music]
Info
Channel: Kekdot
Views: 2,319
Rating: undefined out of 5
Keywords: Blueprints, Unreal Engine 5, Unreal Engine 4, Steam, Multiplayer, Game, Marketplace, Lobby, Game development, Unreal Engine, UE, Multiplayer game, Host game, Sessions, Advanced, Tutorial, Server browser, Sessions Steam, Ready up system, Online, Multiplayer Unreal, Replication, Replicated, MMO, Subsystem, Game Engine, Solution, Modular, Devlog, Listen server, Dedicated Server, Seamless travel, GameMode, GameState, PlayerState, PlayerController, Widgets, RPC's, RepNotify, Multicast, RunOnServer, Variable
Id: jtWhd4ugPW0
Channel Id: undefined
Length: 10min 52sec (652 seconds)
Published: Tue Aug 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.