I built a health replication network in blueprint and I noticed that when server set health on AnyDamage event, it takes time for client update replicated health value so I need to use a delay and wait for the update. I’m not a good programmer yet so I think it’s a bad habit for doing stuff. Can you help me to find out if this is a normal thing to use delay in this situations?
UpdateHealth() executes on the server. SRV_OnHealthChangeActs() runs on the client. This means that SRV_OnHealthChangeActs() will be called with a delay. (until the server call reaches the client)
To really be sure that the correct value received along with the SRV_OnHealthChangeActs() call you can send your NewHealth as an input parameter of SRV_OnHealthChangeActs(). This however should not be required.
You should be aware of network delay it but it should already be handled by the replication system.
Hi @dZh0. Actually when I remove delay node, on first hit of character Health value is intact. so I put delay that fixed it. I read somewhere that the main difference of events and functions is that flow won’t wait for events to finish so that seems correct to me.
There is no guarantee that a RPC (remote procedure call) and the replication of a variable will arrive in the order they are sent. The best way is to exclusively use RPC’s with parameters or replicated variables with a “OnRep” callback and not both if you need something to happen exactly when the variable is received.
Please try to sending your modified health value as a parameter of your event instead of using the delay.
You can alternately change your health to RepNotify which will do a function call OnRep_Health() every time the value is changed.
One more variant is to Bind your widget value to your health value. (although this is kind of a brute-force approach as the widget will check the value every frame)
The reason you should not use the delay node is because this will work only for clients with ping less than 100ms. If your ping happens to be greater you will end up with the same problem.
As you mentioned I used RPC parameter and its working perfectly. Sure I need to read UMG tutorial and rede some of the works. But maybe I do this after my prototype is ready.
Thank you
Just to share: I’ve used repNotify and passing the variable from client to server and neither completely fixes the issue. I’ve been doing this for years and never found a true fix.