Network Spawn HUD on player controlling character only

I have a two player game and am creating a HUD on the character when spawned. The problem I am currently facing is that the HUD for both characters is created on the server and the client. I cannot find the functionality to query whether the character is controlled by the local client, does it exist or am I going about this the wrong way?

What I want:

// If this character is being controlled by the local client (it may not have authority as this will be queried on the Server and Client)
// Spawn HUD
// else
// Do nothing

Thanks in advance!

hey there,

the HUD is attached to your Playercontroller and it “Spawns” for every Client/Controller in your game in the beginning.

The HUD does not belong to a character.

What is your intention in spawning a HUD?

Edit: do you mean the HUD-Class or a Widget?

On Event Begin Play of the character I create a new widget that is the players HUD. The HUD displays the characters health and other attributes. Currently two HUDs are being created for each the server and the client and I want to query whether this object is being ‘controlled’ by the local player and only spawn the widget if that is true.

Thanks for the reply

Ah ok,

then first please use Widget or UI element a.s.o instead of HUD because its confusing for me^^

The moment you set up more than one players, one of them will automatically become a Server and a Client, all others will be just clients. if you are not using a “Dedicated Server”.

So i assume you have more than one of those characters, some are controlled by clients and some not. I would recommend to relocate your “Create Widget” in the Player Controller, because every Client has to get a Controller.

So you wont have to check if a character is controlled. Instead every local player gets a Widget and if he has a possessed pawn, then create the widget and using the pawns attributes.

Ah I didn’t realize that Player Controllers were distinct from Character Blue Prints, and that HUDs existed in another context in the engine. Thank you for clarifying these points for me, I will mess around with player controllers and see if I can get the desired result.

Thank you @anonymous_user_8d708650

I set up a player controller and it works as I wanted now. Thank you again @anonymous_user_8d708650

For future reference of anyone interested:

Each client (including server) gets a unique Player Controller, which is specified in the game mode, so creating local gui elements and other objects are probably best created in the player controller as there is no way to distinct if a character is controlled by one client or another. My understanding is that each instance of the game has one player controller but infinite possible characters so you can be assured when you are creating objects in the player controller that they will be local to that instance of the game.

Feel free to correct me on any points that I am wrong.

im glad to hear that :wink: