# Vehicle Movement Replication is not synced

**URL:** <https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929>\
**Category:** World Creation\
**Tags:** unreal-engine, Physics, Vehicles, question\
**Created:** [July 21, 2018, 2:20pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929 "2018-07-21T14:20:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![zFunked](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zFunked](https://forums.unrealengine.com/u/zFunked)\
**Post date:** [July 21, 2018, 2:20pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/1 "2018-07-21T14:20:56Z")

</div>

Hello comunity,  
i wanted to make a game with vehicles, but the problem is that the vehicles get out of sync after a time or when the vehicle jump over something or so, then this will happen.

 ![248066-screenshot-33.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/7/8/5787b8d9d0347dbc6c1a2c79bc4e149e7094043b.jpeg)

i also made a video to describe the problem better: [- YouTube](https://youtu.be/ejhm1XlmoOQ)

i dont know what this is, but it has something to do with replication. I´m using the Standard PhysX Vehicles.

hope you can help me ^^

zFunked ;D

---

<div class="post-metadata">

**Author:** ![Di-Shiper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Di-Shiper](https://forums.unrealengine.com/u/Di-Shiper)\
**Post date:** [August 1, 2018, 10:51am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/2 "2018-08-01T10:51:15Z")

</div>

Same problem. On version 4.19 everything was fine, after the update I have the same problem.

---

<div class="post-metadata">

**Author:** ![dimburuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dimburuk](https://forums.unrealengine.com/u/dimburuk)\
**Post date:** [August 2, 2018, 6:29pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/3 "2018-08-02T18:29:52Z")

</div>

Same thing! Is the reason really in the engine? Just today I switched to 4.20 for my vehicle game project, and I have my cars on a high building with elimination floor on outside (kinda like derby, you fall you lose). Now I started noticing completely insane replication on 4.20, when I run 2 players + dedicated server and do a small collision between cars, server sometimes think that one car flew off so it ends the game. Imagine my confusion where I see 2 cars standing still on the roof, on both clients, it’s like server didn’t even try to replicate the falling position, just continued consuming input.

Now I’m not saying that the issue is the same, and it could be that I made a mistake somewhere, but I am definitely interested in this thread. I don’t remember it happening on 4.19, but to be honest I didn’t play around with collisions that much.

---

<div class="post-metadata">

**Author:** ![Midas\_de\_Laat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Midas\_de\_Laat](https://forums.unrealengine.com/u/Midas_de_Laat)\
**Post date:** [August 7, 2018, 4:07pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/4 "2018-08-07T16:07:49Z")

</div>

Same problem here. Brand new project with the adv vehicle blueprint. Spawning 2+ vehicles in multiplayer results in off-sets of their replaced representations over time. Easily reproduced by driving in circles with one vehicle and observing from the other.

The player’s position on the server is different from what the client shows (which made me doubt my scripting skills for about 5 hours before noticing all this).

Hope they are aware!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d71a2fac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d71a2fac1](https://forums.unrealengine.com/u/anonymous_user_d71a2fac1)\
**Post date:** [August 8, 2018, 6:29am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/5 "2018-08-08T06:29:55Z")

</div>

I also have this problem in my project after upgrading to 4.20.  
I can also add that i’m having trouble moving the vehicles using SetActorLocation, When running a simple SetActorLocation on the server to move a vehicle to a new location, instead of the client vehicle instantly syncing to the location it now floats towards the location.  
Does anyone else have this happen?

---

<div class="post-metadata">

**Author:** ![Di-Shiper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Di-Shiper](https://forums.unrealengine.com/u/Di-Shiper)\
**Post date:** [August 8, 2018, 6:34am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/6 "2018-08-08T06:34:32Z")

</div>

The problem is already registered, but you can vote for the fix:  
[UE-62345](https://issues.unrealengine.com/issue/UE-62345)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ff8c108b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ff8c108b](https://forums.unrealengine.com/u/anonymous_user_ff8c108b)\
**Post date:** [August 8, 2018, 12:23pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/7 "2018-08-08T12:23:03Z")

</div>

Same here too.

Vehicle replication worked in 4.19 & no longer works in 4.20.  
From what I can tell the vehicle movement for all other clients is synced correctly to the server’s version ( testing 4 clients against a standalone server ).

The physics simulation appears to be running on both the server and the local client, however no client side correction is happening, and so the local simulation diverges very quickly from the server’s version.  
The server’s version of the movement does get replicated to the client as the values in ReplicatedMovement on the vehicle pawn are all correct wrt to the server, but the local client does nothing with them as far as I can tell.  
It does however apply the values for “non local clients” correctly.

Digging further into the code it looks as if this is down to how the new FPhysicsReplication has been implemented, FPhysicsReplication::OnTick skips updating the actor if its role anything other than ROLE\_SimulatedProxy.

The solution seems to be to roll your own client side correction for the vehicle pawn by overriding PostNetReceivePhysicState or OnRep\_ReplicatedMovement. Which would be odd as it was all working in 4.19.

Would be good to get some info from Epic in this respect as I’m sure I’ve just missed something.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ff8c108b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ff8c108b](https://forums.unrealengine.com/u/anonymous_user_ff8c108b)\
**Post date:** [August 9, 2018, 11:45am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/8 "2018-08-09T11:45:33Z")

</div>

I have a workaround.

Turns out that you can replace FPhysicsReplication with your own version.

You need to create a subclass of FPhysicsReplication, and a factory class derived from IPhysicsReplicationFactory to instantiate it.

Override the Tick function of FPhysicsReplication with your own code - all I’ve done here is take the basic implementation from FPhysicsReplication and changed the role check to be for ROLE\_AutonomousProxy.

Then during initialisation register your factory class with the physics engine.

This fixes the issue ( YMMV ).

MyPhysicsReplication.h

```
#pragma once

#include "CoreMinimal.h"
#include "PhysicsPublic.h"
#include "PhysicsReplication.h"

class MY_API FMyPhysicsReplication : public FPhysicsReplication
{
public:
	FMyPhysicsReplication(FPhysScene* PhysScene);

protected:
	virtual void OnTick(float DeltaSeconds, TMap<TWeakObjectPtr<UPrimitiveComponent>, FReplicatedPhysicsTarget>& ComponentsToTargets) override;
};

class MY_API FMyPhysicsReplicationFactory : public IPhysicsReplicationFactory
{
public:
	FMyPhysicsReplicationFactory();

	virtual FPhysicsReplication* Create(FPhysScene* OwningPhysScene) override;
	virtual void Destroy(FPhysicsReplication* PhysicsReplication) override;
};

```

MyPhysicsReplication.cpp

```
#include "MyPhysicsReplication.h"
#include "PhysicsEngine/PhysicsSettings.h"

FMyPhysicsReplication::FMyPhysicsReplication(FPhysScene* PhysScene)
: FPhysicsReplication(PhysScene)
{
}

void FMyPhysicsReplication::OnTick(float DeltaSeconds, TMap<TWeakObjectPtr<UPrimitiveComponent>, FReplicatedPhysicsTarget>& ComponentsToTargets)
{
	FPhysicsReplication::OnTick( DeltaSeconds, ComponentsToTargets );

	const FRigidBodyErrorCorrection& PhysicErrorCorrection = UPhysicsSettings::Get()->PhysicErrorCorrection;
	for (auto Itr = ComponentsToTargets.CreateIterator(); Itr; ++Itr)
	{
		bool bRemoveItr = false;
		if (UPrimitiveComponent* PrimComp = Itr.Key().Get())
		{
			if(FBodyInstance* BI = PrimComp->GetBodyInstance(Itr.Value().BoneName))
			{
				FReplicatedPhysicsTarget& PhysicsTarget = Itr.Value();
				FRigidBodyState& UpdatedState = PhysicsTarget.TargetState;
				AActor* OwningActor = PrimComp->GetOwner();
				if( OwningActor && OwningActor->Role == ROLE_AutonomousProxy )
				{
					if (UpdatedState.Flags & ERigidBodyFlags::NeedsUpdate)
					{
						const float PingSecondsOneWay = 0;
						const bool bRestoredState = ApplyRigidBodyState( DeltaSeconds, BI, PhysicsTarget, PhysicErrorCorrection, PingSecondsOneWay );
						if (bRestoredState)
							bRemoveItr = true;
						PrimComp->SyncComponentToRBPhysics();
					}
				}
			}
		}

		if (bRemoveItr)
			Itr.RemoveCurrent();
	}
}

FMyPhysicsReplicationFactory::FMyPhysicsReplicationFactory()
{
}

FPhysicsReplication* FMyPhysicsReplicationFactory::Create(FPhysScene* OwningPhysScene)
{
	return new FMyPhysicsReplication( OwningPhysScene );
}

void FMyPhysicsReplicationFactory::Destroy(FPhysicsReplication* PhysicsReplication)
{
	delete PhysicsReplication;
}

```

To register your factory with the engine you need to do this sometime during game startup ( during GameInstance Init() seems to be fine ).

```
	FPhysScene::PhysicsReplicationFactory = MakeShareable( new FMyPhysicsReplicationFactory() );

```

---

<div class="post-metadata">

**Author:** ![cyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cyx](https://forums.unrealengine.com/u/cyx)\
**Post date:** [August 10, 2018, 7:27am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/9 "2018-08-10T07:27:11Z")

</div>

Do it according to your steps, the position of the vehicle is synchronized, but the movement is not smooth, very obvious.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ff8c108b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ff8c108b](https://forums.unrealengine.com/u/anonymous_user_ff8c108b)\
**Post date:** [August 10, 2018, 8:02am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/10 "2018-08-10T08:02:27Z")

</div>

You may need to change some of the physics replication parameters. They’ve changed quite a bit from 4.19.

```
[/Script/Engine.PhysicsSettings]
PhysicErrorCorrection=(PingExtrapolation=0.100000,
ErrorPerLinearDifference=1.000000,
ErrorPerAngularDifference=1.000000,
MaxRestoredStateError=1.000000,
PositionLerp=0.000000,
AngleLerp=0.400000,
LinearVelocityCoefficient=100.000000,
AngularVelocityCoefficient=10.000000,
ErrorAccumulationSeconds=0.500000,
ErrorAccumulationDistanceSq=15.000000,
ErrorAccumulationSimilarity=100.000000)

```

I’ve left these at their defaults, but tweaking these may help.

I have also switched over to using the new ReplicationGraph system, it’s much more efficient.

> **[Replication Graph](https://docs.unrealengine.com/5.2/en-US/replication-graph-in-unreal-engine/)**
>
> Overview of the Replication Graph feature and Replication Graph Nodes.

https://player.twitch.tv/?video=v286656883&parent=forums.unrealengine.com&autoplay=false

---

<div class="post-metadata">

**Author:** ![GrumpyNZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GrumpyNZ](https://forums.unrealengine.com/u/GrumpyNZ)\
**Post date:** [August 11, 2018, 11:32am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/11 "2018-08-11T11:32:33Z")

</div>

Hey Slick, thanks for this, could you please provide some more info on how to “register your factory with the engine you need to do this sometime during game startup ( during GameInstance Init() seems to be fine ).”  
Sorry I am a C++tard (will be looking to change that soonish).

Thanks 😉

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ff8c108b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ff8c108b](https://forums.unrealengine.com/u/anonymous_user_ff8c108b)\
**Post date:** [August 13, 2018, 10:17am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/12 "2018-08-13T10:17:37Z")

</div>

Sure,

MyGameInstance.h

```
#pragma once

#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "MyGameInstance.generated.h"

UCLASS()
class MY_API UMyGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:
	virtual void Init() override;
};

```

MyGameInstance.cpp

```
#include "MyGameInstance.h"
#include "MyPhysicsReplication.h"

void UMyGameInstance::Init()
{
	Super::Init();
	FPhysScene::PhysicsReplicationFactory = MakeShareable(new FMyPhysicsReplicationFactory());
}

```

Then you’ll need to point your project at your game instance class.  
In Project Settings, Maps & Modes

 ![250367-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/4/0/440e59e80b7c443ff6733428e421dd1c4f89a628.png)

---

<div class="post-metadata">

**Author:** ![GrumpyNZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GrumpyNZ](https://forums.unrealengine.com/u/GrumpyNZ)\
**Post date:** [August 14, 2018, 12:48pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/13 "2018-08-14T12:48:41Z")

</div>

Awesome, thank you 🙂

---

<div class="post-metadata">

**Author:** ![Xilverback](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xilverback](https://forums.unrealengine.com/u/Xilverback)\
**Post date:** [August 26, 2018, 8:52pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/14 "2018-08-26T20:52:50Z")

</div>

I ran into this problem too. Thanks Slick. Lifesaver.

---

<div class="post-metadata">

**Author:** ![tehKpayne](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tehKpayne](https://forums.unrealengine.com/u/tehKpayne)\
**Post date:** [September 4, 2018, 2:23pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/15 "2018-09-04T14:23:29Z")

</div>

Looking around the new code I see many hints that it’s setup to support client authoritative vehicles… which I have working now by just using Slick’s solution and,

1. Doing nothing on the owner client’s PostNetReceivePhysicState (ignore it and dont try to sync)

2. Adding the RB state to the server update calls from the clients. The server is just snapping to the client’s version right now.

I haven’t had a chance to test this with other people, in true mp, but I suspect there’s many problems with the fact there’s no way for the server to hard correct the owner client right now. I’m sure there’s many ways, but I’ll probably try doing a check in PostNetReceivePhysicState and if the error is large then snap the owner client.

Ideas?

---

<div class="post-metadata">

**Author:** ![zFunked](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zFunked](https://forums.unrealengine.com/u/zFunked)\
**Post date:** [September 4, 2018, 6:05pm UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/16 "2018-09-04T18:05:17Z")

</div>

Hey tehKpayne,  
sorry for the late response, we don´t want to use C++. We made an C++ Project lastly for learning purposes and added some content packs after that the whole script won´t recompile because VS2017 said that there were over 200 errors. So i´m letting my fingers out of c++ for now.  
There must be a solution for this …  
I´m really confused now

---

<div class="post-metadata">

**Author:** ![Kieranator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kieranator](https://forums.unrealengine.com/u/Kieranator)\
**Post date:** [October 10, 2018, 11:03am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/17 "2018-10-10T11:03:07Z")

</div>

I also have this problem as of version 4.20

---

<div class="post-metadata">

**Author:** ![StuntThumper88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@StuntThumper88](https://forums.unrealengine.com/u/StuntThumper88)\
**Post date:** [October 30, 2018, 2:44am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/18 "2018-10-30T02:44:57Z")

</div>

Epic is claiming its fixed in 4.21! [Unreal Engine Issues and Bug Tracker (UE-62345)](https://issues.unrealengine.com/issue/UE-62345)

---

<div class="post-metadata">

**Author:** ![Yakim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Yakim](https://forums.unrealengine.com/u/Yakim)\
**Post date:** [November 8, 2018, 1:33am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/19 "2018-11-08T01:33:37Z")

</div>

Yes, this problem is solved, thanks to everyone who voted =)

> **[ReplicationMovement bug UE 4.20](https://forums.unrealengine.com/questions/810707/replicationmovement-bug-ue-420.html)**
>
> Why does not the owner pawn replicate, and others replicate? Video https://youtu.be/Vg6vN9FxAC4 Sample project https://drive.google.com/open?id=1rBZ96Qj6BlBNJrkVVl1dbt8BH2t2OyZy If you enable replication of the cube component, it starts to...

---

<div class="post-metadata">

**Author:** ![StuntThumper88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@StuntThumper88](https://forums.unrealengine.com/u/StuntThumper88)\
**Post date:** [November 10, 2018, 2:09am UTC](https://forums.unrealengine.com/t/vehicle-movement-replication-is-not-synced/429929/20 "2018-11-10T02:09:11Z")

</div>

Is anyone having this issue in 4.21? It seems to be better, but I cant find any way to keep them 100% synced other than an ugly long polling setup. I’ve tried replicating dif components, with or without the new Replicate Physics to Autonomy. I cant find any combo to get vehicle replication correct
