Download

Updating Client UI Not Working

Hello fellow UE4 users,

I have an issue that has been plaguing me for a week or so now:

I am trying to create a very simple server based multiplayer game. I have set up character movement, damage, death etc and it is all working as wanted.

However, I cannot get the client UI to update at any point. I believe this to be because the server is recieving all the UI calls but I cannot for the life of me figure out how to fix this.

Here is my damage function:

HealthHandling.png

In brief, if it receives a damage event, it alters the characters health, calls the UI update, checks for death (and if dead ragdolls the character etc) then returns

Here is my health UI graph:

healthuibp.png

When it receives an update call it should simply set the progress bar percentage, however this call is never reached on the client. It works when one player is present and not running a dedicated server, but as soon as I switch it to a server it ceases to work.

Any help would be greatly appreciated.

Set the values of health, max health, stamina, and max stamina in the character/controller. Make sure the variables are marked ‘Replicated’. These values should be modified on the server either through custom events that are set ‘Run on server’ or through events such as AnyDamage which can only be ran on the server, never from the client.

Create the HUD widget as normal, on client, and pass a reference (on client) to either the character or it’s controller. In the HUD Widget, in the designer tab, create a binding for percent bars and colors (or you can do this in the event graph, but not from your event) and use the reference you passed earlier to pull these values instead of passing them through an event. That should work.

The problem is that Any Damage is only run on the server. UI only exists on the client. You’re calling an event dispatcher on the server version of your BP, which doesn’t know that your UI has an event bound. Another way to fix this would be to have an ‘update UI ROC’ function that calls the client back and run your dispatcher from there; but that’s not as clean as replicating the health/stamina values (which is a good idea anyway) and just pulling those values from a reference.

Also if you want, where you’re updating the fill color and opacity… take one of the ‘In Color’ pins, drag it to the left and release. Type ‘Select’ into the context box. You can then take your boolean from the ‘< .2’ node and drag it over to the wildcard ‘index’. Now you can set the colors there and you won’t need the branch. The select node is pretty versatile and isn’t limited to booleans. You can do the same with a ‘Lerp’ node which would take your fill percent. That would smoothly change from green to red (or vice versa) as the bar drained. Two bonus suggestions for you.

That’s worked a treat, thanks a lot. I bypassed the UI event graph completely and created a binding to get the health/stamina percent (which is now calculated on the player character) from the player character. Of course it was going to be something as simple as that!

Again, thanks. Many headaches have been averted.