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:
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));
}
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.