C++ SetRelativeLocation() for multiplayer on a component for Custom positions like Prone

I’m posting this to help anyone out and also my future self should I forget.

The goal: I was recently trying to implement prone position on Third Person FPS using C++. To do this I had to Lerp my Mesh relative to the location of the capsule using GetMesh()->SetRelativeLocation() otherwise it would lay below the ground’s surface when the capsule shrinks.

The problem: Simply Lerping using GetMesh()->SetRelativeLocation() works fine on the Listen Server, but not on the clients. Client’s mesh would still lay below the surface.

The solution: Be sure that when you use GetMesh()->SetRelativeLocation() that you also set an FVector variable that’s part of the ACharacter Class called BaseTranslationOffset to the same value. Setting this value alone will cause the correct behavior on the Clients but not the Server. Of course you must still use these functions on ther Server and/or using RPC calls.

			GetMesh()->SetRelativeLocation(MeshCurrentRelativeLocation, false);
			BaseTranslationOffset = MeshCurrentRelativeLocation;
1 Like