Multiplayer Pawn movement synchronization problem

I have a APawn controlled by a player controller on the server and the client.
Now I dont have any movement components, I just use SetActorLocation and SetActorRotation to move the pawn around.

In a network game, the server’s pawn is correctly rotated and positioned on the client, but the client is not correctly rotated and positioned on the server

void AActor::GatherCurrentMovement()

I notice the server will gather the position and location and send that to the client, so I would think the client should at least jump to where the server thinks the actor should be, but this does not appear to be happening.

Why could the client APawn be out of sync?


I don’t know if this provides anything but I had a similar problem (Actually I still have it, just “fixed” it with a workaround):

My pawn’s (not characters that can use the cool CharacterMovementComponent :frowning: ) position would slowly differ between server and client when moving, it stacked up more and more over time. To fix that I used a custom FRotator/FVector containing position/rotation and saved the server position/rotation in it, replicate it to the clients and use a RepNotify to override it. I still do not know why and how this happened, but maybe someone has a solution/idea what is happening!

Good luck :slight_smile:

Doing more searching looks like AActor::OnRep_ReplicatedMovement() isnt being called on the client

Have you got Replicates Movement checked, or set to true in the file?

That should force-update the position of the pawn from the server regularly.

yeah replicate movement is enabled, and I also tried setting bAlwaysRelevant = true

It looks like AActor::OnRep_ReplicatedMovement is being called correctly on those actors the server is responsible for controlling, just not for the actor the connected client is responsible for controlling :-/

hrmm I have a wild hunch, could it be that, the client sends the data to the server, the server then doesnt send any data back as it sees that the data has not changed somehow? this wouldnt really seem to be a valid theory as the actor on the client is not related to the actor on the server, both are out of sync in regard to position and location.

okay i found the problem:

in AActor::GetLifetimeReplicatedProps:

DOREPLIFETIME_CONDITION( AActor, ReplicatedMovement, COND_SimulatedOrPhysics );

then in APawn::PostNetReceiveLocationAndRotation:
if( Role == ROLE_SimulatedProxy )

so my Role is ROLE_AutonomousProxy

I’ve managed to hack around the issue by:

replicating the movement data myself, then faking a role change before applying the movement:

while not ideal, this works. Is there a better way to solve my problem thats not hackey?

That’s odd, Pawns should almost always be SimulatedProxy by default anyway since they’re owned by another controller.

It’s not because your Pawn is already in the level before play has started it is?

on the client computer the pawn the client is controlling has
RemoteRole = 2 (auto proxy)
Role = 3 (authority)

I see the ut4 code only sets this in 2 places:

I figure its one of these causing the problem.

The problem is not with the pawn the server is controlling (this is in sync and working), the problem is with the pawn the client is controlling (this is out of sync).