Replicating SetActorLocation

How do I go about replicating this movement function? I need to use a timeline with setactorlocation for gameplay abilities in my project but it causes jitter on clients over netplay.


I’m not sure. I struggle with getting smooth network movement when I use anything other than the built-in smoothing of the CharacterMovement component.

Something to keep in mind that might help though, is that when you set an Actor to Replicate Movement, then the server will force the clients to update to the server’s version of the actor’s location whenever it does another update to the clients. If both the clients and the server are telling the character to set its location, then even if they start the exact same movement at the exact same time, then you’ll get this problem:

  1. Server and Client both start the exact same movement at exact same time.
  2. 100 ms later, Server and Client have both moved the exact same distance (say 25 Unreal Units of distance). Server sends location/movement update to Client saying “your location has moved 25 UU”.
  3. Server moves 25 more UU. Client moves 25 more UU. They should both be at 50 UU traveled.
  4. Client receives update from server at 120 ms. The update says the pawn has moved 25 UU.
  5. Client obeys the server because movement is replicated, and resets the location to have only traveled 25 UU.
  6. Server sends another update saying “What are you doing? You’re supposed to be at 75 UU from the start position by now!”
  7. Client receives the replication update. “Oh, sorry! Fixing it now.”

Hence the jitter.
Now it’s not quite that bad because Velocity is also replicated, so any missed position updates are filled in by the velocity moving the character in between network updates (but will have to jitter-adjust if there was a change in direction, if there’s no network smoothing).

Now, if you’re using CharacterMovement component, then eveything I just mentioned gets smoothed over and hidden by the nice built-in smoothing algorithms. So then why is it still jittering?

I could be due to that timeline you have going there. Differences in framerate between the two machines, plus ping delays, are probably not smoothed by the charactermovement algorithms.

I’m not sure how to fix this as I’ve never succeeded in getting smooth movement on anything that’s not built-in charactermovement, but it might be worth trying to tell it to stop replicating movement until the Timeline is finished, then turn movement replication back on with a lerp or something. IDK. If you figure it out, let me know!

Best solution i found was to detach Mesh from the Actor ONLY for locally controlled Actor, set Actor Location in event tick or timer for all of them, set World Location for the Mesh of the locally controlled Actor again in an event tick, and then at the end set Actor one last time with an RPC for all to match the Mesh position of the locally controlled Actor. Then attach mesh to the Actor again for the locally controlled Actor. During process you can enable Camera Lag and set camera lag speed to a lower value for the locally controlled Actor for less stuttering. So, basically you control the motion with setting root position for the locally controlled actor locally and then try to imitate this motion by setting Actor Location for all.

Also keep in mind that if you’re using a CharacterPawn then the movement is replicated and smoothed FOR you without adding any scripting about it, based on AddMovementInput.

I’ve been trying to figure this out as well. In my case, the server replicates perfectly but the client jumps through the timeline and reacts a second later. I tried hitting “replicate” in the timeline to no success. I used a Multicast RPC right before the SetActorLocation that includes the New Location pin.

Seems like setting Gravity Scale of Character Movemet to 0 and using “Add Impulse” function works smoothly.

Are you using a replicated timeline AND an RPC? The client might be getting different updates from each. Try removing the RPC.

Setting this in beginplay helped with me, allowed me to set actor location on the client and not have the server rubberband me back.