Begginer question about replication

Hi all,
I am a begginer on working with network and replication, and i have a question that i think is simple. I created a simple third person in which a player collides with a block and an INT variable is incremented. After 15 seconds the server prints both player scores on the screen. Problem is that only one of the players score is updated. I will add some screenshots of my blueprints.

This is what happens when a player overlaps a cube.

This is the event that is called on the player. The boxes variable is replicated and is used to store how many boxes i caught.


This is the game mode event that after 15 seconds prints both players score on the screen.

This is what is printed. Both players had a score of 3, but only one is printed correct. Ignore the 0, is work in progress UI, it does not have it’s functions yet.


you can also find my project here: GitHub - Xadovsk/UE4NetworkTEst

thanks in advance.

Here’s a beginners response :slight_smile:

I think here is where you need to have a Replicated Function to tell the server that the score should be updated.
1.5 - Function Replication | Unreal Engine Documentation.

Hi, you can either

(1) make the “Col” event a RunOnServer RPC

(2) don’t use “GetPlayerPawn” to check whether the “OtherActor” is a player but rather add a tag e. g. “player” to each player pawn and then use “ActorHasTag” to check whether the “OtherActor” is a player

Cause your current logic will work fine on the server but fail for the clients. “GetPlayerPawn” with index 0 will return the server player pawn when called on the server and the client player pawn when called on a client. OnComponentBeginOverlap will be called on both server and client since it is happening on both of them. But you want to execute the “Col” event on the server. Now if the clients pawn overlaps the box, then the client will execute the “Col” event (therefore making it a RunOnServer event will solve the issue) but the server will not since the “OtherActor” which is the client pawn is not equal to “GetPlayerPawn” with index 0 which is the server pawn (since the server is currently executing this). If you would use a tag instead to check whether the “OtherActor” is a player pawn, then it will also return true on the server and the server will execute the “Col” event.

By the way, I would prefer the solution with the tag, since the server is already executing this and therefore there should be no need for an RPC.