Sending variable to HUD when changing

Hi, I need to send the Health variable to the HUD when it’s changed on the server. How can I do this?

The easyest way whould be to use a callback method on the replicated variable.


UPROPERTY(ReplicatedUsing=OnRep_Health)
float Health;

UFUNCTION()
void OnRep_Health();

When the value changes server side, OnRep_Health gets called.
And you can do what you need to do when the value is updated from the server and replicated to the client.

Yes, but how can I send that variable to the player’s HUD?

Its hard for me to say with out knowing how your HUD is setup/ working.
Are you using Canvas, Slate or UMG for the HUD?

Basicly the execution chain whould go something like this.
Server Changes Health > Healt Replicated To Client > Callback method called on client > Update HUD veriable for health > Update/ Redraw HUD.

Since most of these values are extracted by the functions bound to the various HUD elements, I have found it easier to just get owning pawn, cast and get direct access to values from the HUD BP in stead…

Yes that will do it :wink: i just assumed OP was trying to do it in code.

I want to create a Widget Blueprint HUD but I don’t know how to create the widget in MyCharacter.cpp. With the blueprints I can use this:

http://puu.sh/dzKZj/79ce7bf8bc.jpg

but what I have to do in C++?

I wrote this a time back.
[Tutorial/ Snippet] Creating a UMG Widget in C++, and delegate example.]([TUTORIAL/SNIPPET] Creating a UMG Widget in C++, and delegate example - Programming & Scripting - Epic Developer Community Forums)
Let me know if something is not clear.

Visual Studio gives this error:

http://puu.sh/dzVwe/d5cc288bbe.png

We really need a hand with this issue. It’s breaking our workflow :frowning:

Solved. I used the function CreateWidget to create a Widget based on the Widget Blueprint.