# Movement replication works on client, but not on host

**URL:** <https://forums.unrealengine.com/t/movement-replication-works-on-client-but-not-on-host/679717>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 29, 2022, 7:01pm UTC](https://forums.unrealengine.com/t/movement-replication-works-on-client-but-not-on-host/679717 "2022-10-29T19:01:42Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![rubm123](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rubm123/32/476292_2.png) [@rubm123](https://forums.unrealengine.com/u/rubm123)\
**Post date:** [October 31, 2022, 9:13pm UTC](https://forums.unrealengine.com/t/movement-replication-works-on-client-but-not-on-host/679717/18 "2022-10-31T21:13:49Z")

</div>

Thanks a lot!

This is my code that finally works:

[AMyPawn](https://github.com/rubenmoor/TutorialMPBasics/blob/main/Source/TutorialMPBasics/Private/MyPawn/MyPawn.cpp), not much going on there. Only

- Replicate Movement: false, no need to replicate location or anything
- Replicated property: velocity, this together with the tick function takes care of correct movement

> Not a fan of updating parameters on tick. It can cause desync between client and server

This is valuable advice indeed. As this is just a multiplayer learning experience, I simply removed the dampening from the tick function such that velocity only ever changes when I hit a button. If I were to implement dampening and I just had to change the velocity in the tick function, I would chose _not_ to replicate `velocity` and instead, I would use a client rpc to make sure `AccelerateLeft` and `AccelerateRight` get executed on the client.

And [MyPlayerController.h](https://github.com/rubenmoor/TutorialMPBasics/blob/main/Source/TutorialMPBasics/Public/Modes/MyPlayerController.h) and [MyPlayerController.cpp](https://github.com/rubenmoor/TutorialMPBasics/blob/main/Source/TutorialMPBasics/Private/Modes/MyPlayerController.cpp)

Two design choices here:

- I created an enum for all the actions. This is unfortunately redundant with unreals action binding system, but I use the `EAction` enum in `SetupInputComponent` to define only once what will happen at both client _and_ server. This way, I can’t accidently move left on the client and right on the server due to some copy-paste mishap
- `BindAction` then takes care of registering both cases, server and client. This implies use of closures, otherwise I can’t use the `EAction` parameter. `HandleAction` is where stuff actually happens and `ServerRPC_HandleAction` only wraps that one.

---

_[View the full topic](https://forums.unrealengine.com/t/movement-replication-works-on-client-but-not-on-host/679717)._
