ReplicatedUsing is not called for replicated property

Ok so, for the sake of simplicity I’m only going to talk about one variable though there are many that aren’t working.

I have a sidekick that I am spawning in via a server RPC. In this RPC, I am also setting that newly spawned sidekick’s health. I am wanting that health to be replicated to all clients that are connected. However, I am noticing that the ‘ReplicatedUsing’ function that I’ve setup is not being called at all. Does anyone know why that might be?

Here is a (simplified) version of the server RPC that spawns the actor and sets its health. I will also include the declarations of the health property and my GetLifetimeReplicatedProps.

Server RPC that Spawns the Actor & Sets Health in ATrainerController (I.e. the player controller) class:

void ATrainerController::SpawnSidekick_Implementation(ATrainerController* TrainerController)
{ if (Role == ROLE_Authority)
  [INDENT=2]TrainerController->Sidekick = GetWorld()->SpawnActor<AMonster>(SpeciesClass, TrainerController->GetTrainer()->GetActorLocation(), TrainerController->GetTrainer()->GetActorRotation());



Health Declaration in AMonster class:

UPROPERTY(ReplicatedUsing = OnRep_Health) float Health = 100.f;


OnRep_Health Declaration in AMonster class:

void AMonster::OnRep_Health()
{ // Just doing a simple print statement to see if this is event getting called...
  GEngine->AddOnScreenDebugMessage(-1, 200, FColor::Green, FString::Printf(TEXT("Health %s"), this->Health));


GetLifetimeReplicatedProps in AMonster class:

void AMonster::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const
{ Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AMonster, Health);


OnRep_Health has to be a UFUNCTION() in your header file :wink:

Sorry forgot to include that bit @RemzDNB, but it already is.

UFUNCTION() void OnRep_Health();

Are you running a listen server by any chance?

Yes I am [USER=“2626”]Stefan Lundmark[/USER].

This is a pet peeve of mine. UE4 does not call RepNotify methods in C++ on server objects. On a listen server the client isnt really a client. Blueprints have a special code path for this.

If you try as a dedicated server, it works… Right?

You can choose to call the On_Rep function on the Server to get the same behavior as in Blueprint. Listen-Servers can be a bit tricky when trying to separate Server and Client logic, this is a lot easier on a dedicated server.