Variable is valid on server but null on client

I’m trying to update my clients HUD when it takes damage.
I have a blueprint component on the player character that contains relevant player status variables like health
and an interface to interact with it from outside of the blueprint (if needed)

My HUD is initialized on the controller, but hit events from projectiles (ect.) happen on the actor level.
So im trying to pass a reference from my controller to my pawn about its HUD, so i can update it when the current health variable is changed by the server.

Everything is working fine, each controller is aware when its health changes with rep notify, each players health is unique.

The trouble comes with trying to update the hud, if i do something like getController > get HUD > set HUD reference on player character. The hud variable on the character is only valid on the listen server, so only the servers hud updates. If i shoot a client and try update its hud i get a null reference.

If i throw in a bunch of debug print strings for the process, most events that should be running client side are coming from the server, at least thats what im getting from the debug message “server: Hello World”
So i guess for some reason, the setting of the HUD is only happening on the server, so the client isn’t aware of that variable locally.
I can’t figure out why its not running client side even when i call a simple event to set the variable on possessed pawn from the controller (which isn’t replicated)

I swear this is my super power; To solve issues minutes after I post online asking for help.
this seems to work for future visitors;

When i set the HUD widget, cast to controlled pawn and set the hud reference by owning client event of the player status component (this fixes the null reference and ensures that only the client is calling it and returning the value associated to that client)
I had tried this before but i thought it was broken because the value didnt update on the hud, that’s because i was trying to do it all within the rep notify function, but i needed to pass that value out as a client side value, so again set up a owning client event and passed the server variable down to the client.

TL:DR:
Use owning client functions, make sure when you’re reading variables that the server touches, to pass it through client side functions otherwise the server still has authority over it, and you don’t want the server to have to deal with displaying things only the client can see.

3 Likes