Dedicated server : hud from player controller is null

Hi everyone,

I’m trying to make my game work in dedicated server in order to have everything up and running before implementing the multiplayer but I’m facing a big problem.

The variable **MyHUD in the PlayerController is always null **. I don’t really understand why, I put some breakpoints and the HUD is properly set in the Gamemode and is not null when I check, it’s just missing in the playercontroller while there is no problem when we’re not playing in dedicated server…is there something I’m missing ?

I thought that the Player’s HUD is client-only and not replicated so I assumed there was nothing in particular to do… I’m confused.

help … u.u

Are you sure that you’re trying to get the HUD on client side? On ServerSide it could be NULL.

As eXi said HUDs are only on client side not server, i don’t know why you have set it up on GameMode. Generly in multiplayer your HUD should a autonomous and read from GameState and PlayerState about replicated game state.

I just wanted to check my HUD and it is by default stored in the controller. I just used the Unreal functions GetFirstPlayerController()->GetHUD() and it always returns null. Everything I do is Client side, isn’t it ?

What I meant by set up in GameMode is just that when you check the editor, it is there (and set from the editor when you change the gamemode through the world settings). My HUD is auntonomous, I just wanted to access it for one particular player.
The HUD is by default stored in the playercontroller. I just used the Unreal functions GetFirstPlayerController()->GetHUD(), it’s client side too, no ? I’m confused, it returns null all the time.

It’s not about the function - It’s about the place where you call it.

In Multiplayer, there are several classes that have specific instances only on the Client or Server. For example the PlayerController. It exists only one time on each client, but the Server has one for every client. Means a Client can’t access the other Clients PlayerControllers.

Another example is the GameMode. The GameMode only exists on the Server.
Even if you call you function there, it will be called on the Server and will never reach the Client.

Since you said that it is only working if you don’t use a DedicatedServer, i assume you are calling it on the Server, because a ListenHost would be a client and getting the HUD on the Server would actually work, because it is also a client. The Dedicated Server on the other hand is not a Client. If you call the function on him, you will get the NULL as return.

It would be nice to know WHERE you are calling this function. I could be wrong with the GameMode, but it all looks like exactly this. :smiley:

I tried calling from the GameMode first but then moved it to the Gamestate… something is odd though. When I put a breakpoint directly in the PlayerController and check the value of the myHUD variable, it is always NULL (which explains why the function returns NULL … ). Why is NULL, I understand the whole depending from where we call part…but here, I was checking directly from the controller itself.
Did I do something wrong ?

Even the controller has a Server Version. You will need to check if you are on the Server or on the Client.

if(Role == ROLE_Authority)
{

      // Do Stuff only if we are on the Server Version of this Actor
}

// or

if(Role < ROLE_Authority)
{

      // Do Stuff only if we are on the Client Version of this Actor
}

I didn’t know that. I moved everything in the Gamestate and made sure to iterate on the controllers to get the local ones and I get a value my HUD. Thanks very much for taking time to explain :smiley: