Null pointers at HUD on multiplayer

Hello,
On my multiplayer game i recieve null pointers on get owning player character and state, i had them on Drawhud function i moved them to Begin Play and in both cases i receive null pointer why?

my begin play:

void ADSProject_Hud::BeginPlay()
{
Character = Cast<ADSProject_Character>(GetOwningPawn());
Pstate = Cast<ADSProject_PlayerState>(GetOwningPawn()->PlayerState);
}

and here how it was on my drawhud function

ADSProject_Character* Character = Cast<ADSProject_Character>(GetOwningPawn());
ADSProject_PlayerState* Pstate = Cast<ADSProject_PlayerState>(GetOwningPawn()->PlayerState);

what i am missing? i am assigning the variables myflags,otherteamflags and totalflags on the contstructor of the class.

Just a suggestion. Did you try to set them in the “void ADSProject_Hud::PostInitializeComponents()”- function, as the pawn may not yet exist on BeginPlay()?

BeginPlay is called after PostInitializeComponents

https://github.com/EpicGames/UnrealEngine/blob/69b5693c869697b828e1f2c24004ff1481b5fb98/Engine/Source/Runtime/Engine/Private/Actor.cpp#L2283

If you look on code difference between those to is that BeginPlay is only called when world is play mode, where PostInitializeComponents is also called in level editor mode

I suspects your problem might be related to replication, as server does not need HUD

I Know HUD is locally and every player has their own. Get owning pawn doesn’t get the one that the HUD belongs? I have those variables as replicated on the playerstate class. Also the HUD draws the health and ammo but doesn’t crash.

I have health and ammo in the character class. I will check again after work if I forgot something relevant to this.

I saw about the replication thing in another post but I want to understand why.since in my mind should print something even 0.local HUD calls the local player to get a value.

I moved the 3 variables on the player character from the player state and was fine. i removed the replication on them and tried different combination was crashing.

Now the only thing that left on player state is the teamNumber variable and the getter and setter and still crash, it seems if its exactly the same on player character doesn’t crash and there is a problem with hud and player state why?

I think hud should be in client only and get values from other replicated object, theres no point for server to deal with hud

I am totally confused. the values are from local ones…
ok, i have a hud class and i want to access a value from a player state, how you would do that?

The problem was that hud is part of the player controller while my class ADSProject_Character was inheriting from the character class,which isn’t direct connection and the reason that was returning NULL.