I’d like to have my character’s energy bar to slowly drain while a certain ability is active. I know I can use the delta time on the tick to get a smooth drain, but since it is a multiplayer game and that variable is replicated, wouldn’t this cause some traffic issues? Is there a ‘right’ way to do something like this?
Having the energy drain in a Function would enable you to use a Timer on it so that it is tracked more accurately.
Set Timer, put the EnergyDrain Function on it, set it to a time you want. Stop/Pause/Clear Timer to stop it when you don’t want it to drain anymore.
The engine will automatically tick it off at the set intervals, leaving your code to do other things with its Time.
Setting the timer to something pretty fast wouldn’t have any of those same network traffic downsides?
Network traffic which stated in UE as ‘Replication’ is not working that way. You can drain your energy millions of time per frame and make it replicate(update) once every second. This is will be heavy on server-side CPU,as it will do many calculations every frame,but will be relatively lighter on network,as server sending a few numbers every second.
In reverse;you can set your drain happens (let’s just say) 1 point every hour but make it replicate 1000 times every second. This will be virtually weightless on CPU but will hurt your network transfer capacity.
Okay, I see now. So variables aren’t updated on the client each time it changes? It works more on an interval, and between those intervals anything can happen that the clients aren’t necesarily guaranteed to know about?
I don’t think so, as far as I know, the variable replicates every frame as long as it has changed since the last replication, I think what they mean is that you have a 2nd variable that represents your variables (and you modify the 2nd variable) , and when you want your real variables to replicate, you just set your real variables to the duplicate 2nd variable, this would essentially allow you to control when they replicate.
I guess doing that would also make the progress bar drain animation smoother too, just have to do a bit more writing.
Yes,clients can miss information in certain circumstances. If someone dies and if it doesn’t replicate on client,that client will see that person is still alive. However client will not be able to do damage or etc. So dead person will stay look alive forever. There is a ‘RepNotify’ function for this. Jamen’s idea is a very good one. Try it out. Also you should check Epic’s Official Tutorials about networking on Youtube. They will allow you to grip the basics.