Initializing and updating PlayerState in GameMode - Multiplayer

Hi,

I created a custom PlayerState called OrbPlayerState and assigned it to be default PlayerState in OrbGameMode. I created two variables called Health and MaxHealth in OrdPlayerState and made them replicated.

OrbPlayerState.h

class PROJECTORB_API AOrbPlayerState : public APlayerState
{
	GENERATED_BODY()

protected:
	/** Used to tell UE which variables to replicate */
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
public:
	/** Holds player health */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Replicated)
	float Health;
	
	/** Holds player max health */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Replicated)
	float MaxHealth;

	/** Constructor */
	AOrbPlayerState();
};

I made MaxHealth also as replicated because there might be some powerups or items that can change the MaxHealth and I want it to be reflected in client.

In OrbGameMode’s PostLogin, I set the Health and MaxHealth of PlayerState.

AOrbGameMode.cpp

void AOrbGameMode::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);

	// Setting the player MaxHealth and Health.
	AOrbPlayerState* playerState = Cast<AOrbPlayerState>(NewPlayer->PlayerState);
	playerState->MaxHealth = 100.0f;
	playerState->Health = playerState->MaxHealth;

	UE_LOG(LogTemp, Warning, TEXT("PostLogin: %d"), playerState->MaxHealth);
}

On server, the log shows PostLogin: 0

And inside the Character (client side), I get PlayerState and printing the Health and MaxHealth.
Log in client shows “Client 1: Health: 100, MaxHealth: 100”

Even after setting the MaxHealth in before line, log shows MaxHealth is 0. Whys is that? But then, Client knew that MaxHealth and Health are 100 and 100.

What is going on here? What am I doing wrong?

How to initialize PlayerState and update in GameMode and make sure that it is effected in Client?

OMG. My bad. I was discussing with friend of mine about the problem. Values are replicated correctly. Both Health and MaxHealth are floats but i’m trying to print them using %d.