Draw player HUD in multiplayer

Hi guys!

I’m a french student just trying to develop a simple multiplayer game. I want to draw a basic UMG (with a health) for each player. Variables such as life, armor etc are on my character’s blueprint and are set to replicate. This character blueprint also have a GetHealthRatio function.
I have a player controller which should initialize the widget and character reference and the widget reference. He also has to initialize the content of the widget and display it on the player’s screen.

This is quite good but, even if the picture of the HUD is drawn, the health percent does not appear whereas it does in SP mode… I know I certainly did a mistake on authority setup (sorry i don’t have the real good words…) and I hope you’ll be able to give me some tips in order to solve my issue.

Here are my blueprints :

It is quite hard to tell what is wrong when we are talking about muliplayer. Make sure you enabled replication for Actor were you are going to replicate variables (Class Defaults → Section Replication → Replicates). Be careful of using Get Player Character from Player Index. In multiplayer it may return Server-version of the Character when it it will be called by Server.

First of all, i verified if the PlayerCharacter was replicated and the Replicates checkbox is well checked. Variables are replicated too.

So you tell me to be careful using GetPlayerCharacter from PlayerIndex, but I don’t know how to do it properly… I read somethings about GetOwner which returns an Actor and that I linked to CastToPlayerCharacter in CreateWidgetAndReferences. And it still doesn’t work.

Here is my error log :

Error Blueprint Runtime Error:
Accessed None trying to read property
CurrentCharacter from function:
‘InitWidgetContents’ from node:
Get Health Ratio in graph:
InitWidgetContents in object:
MyPlayerController with description:
Accessed None trying to read property
CurrentCharacter

I’ve it as many as I have players.

I guess I’ve a problem in initialisation or in networking.

“None” in blueprints is “null”, so “Accessed None” means you trying to call function on from null (blue link connected to “Target” pin is None)

My guess is you doing wrong cast, UMG widget is owned by PlayerController not Character or Pawn, you can get those from PlayerController

Try to Get All Actors Of Class and check returned array for any Characters. If you have one Client connected you can get the first element from array and try to call function this way.

Isn’t it what I am doing ? I get the GameHUDWidgetRef from the PlayerController as far as I know. Did I misunderstood you ?

Thanks for your answers that might be good but I don’t understand or I don’t know what do you mean by “Get All Actors Of Class”.
Do you mean get All Player Controllers instances ? If so, how can I do it ?

I do not know what the problem is, but I would recommend check this tutorial if you have not already, it will give you great insight on multiplayer systems in UE4:

In place where you want to use your Current Character, call Get All Actors Of Class (set class of your Character) and check if length of returned array is > 0. If there are Actors in the array and your variable is still None, that means there is a problem with initialization of Current Character. But still you can use “Get” function for this array and this will return your Character if there is any.

Thanks for your answer. I tried just what you told me: replacing Current Character (in my PlayerController Blueprint) and it works on a way…
In fact, I do not know how to get the good player via the Get All Actors Of Class?
How can I get a Current Character reference via this array