# Physics go haywire and inconsistent when using "RecreatePhysicsState"

**URL:** <https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623>\
**Category:** World Creation\
**Tags:** wheels, physics-stability, vehiclemovementcompo, unreal-engine, UE4, question, CPP\
**Created:** [December 17, 2019, 7:13am UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623 "2019-12-17T07:13:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8474b73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8474b73](https://forums.unrealengine.com/u/anonymous_user_c8474b73)\
**Post date:** [December 17, 2019, 7:13am UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/1 "2019-12-17T07:13:37Z")

</div>

we wanted to replace the vehicle wheels during runtime and when we use “RecreatePhysicsState” the physics of the vehicle become very inconsistent. Here are the 3 ways it can go:

1. physics go crazy and car starts flying around like a deflating balloon.
2. car falls through the landscape and causes the engine to crash.
3. It suddenly decides to work properly.

Due to this inconsistency I would like to know if there is a proper way of replacing wheels during runtime or before spawn or before the constructor of the WheeledVehicleMovementComponent4W is called.

---

<div class="post-metadata">

**Author:** ![Koraemon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Koraemon](https://forums.unrealengine.com/u/Koraemon)\
**Post date:** [December 17, 2019, 7:40am UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/2 "2019-12-17T07:40:04Z")

</div>

Here is how I replace my tires. In my game, I replace my existing tire for empty tires to simulate a flat tire feeling. After replacing the certain tires with my empty tires. I remake the tires by running the follwing:

```
    GetVehicleMovementComponent()->WheelSetups = EmptyWheelsSetup;
    GetVehicleMovementComponent()->CreateVehicle();
    GetVehicleMovementComponent()->RecreatePhysicsState();

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8474b73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8474b73](https://forums.unrealengine.com/u/anonymous_user_c8474b73)\
**Post date:** [December 17, 2019, 7:48am UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/3 "2019-12-17T07:48:04Z")

</div>

that’s what I’ve been doing too. I replace the existing tire, then do the exact same thing. but the physics then do one of the 3 things mentioned above. it happens when it checks for if the new transform is valid.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8474b73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8474b73](https://forums.unrealengine.com/u/anonymous_user_c8474b73)\
**Post date:** [December 17, 2019, 9:17am UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/4 "2019-12-17T09:17:57Z")

</div>

just had a look at the actor bounds for collision. and for the vehicles they’re massive. why is that? then it’s no wonder that the other error is that the bounds aren’t right.

---

<div class="post-metadata">

**Author:** ![Koraemon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Koraemon](https://forums.unrealengine.com/u/Koraemon)\
**Post date:** [December 17, 2019, 10:48am UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/5 "2019-12-17T10:48:21Z")

</div>

Can you show me how you replaced your tires via Code?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8474b73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8474b73](https://forums.unrealengine.com/u/anonymous_user_c8474b73)\
**Post date:** [December 17, 2019, 2:46pm UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/6 "2019-12-17T14:46:43Z")

</div>

sure.

```
UPCCVehicleMovementComponent* movementcomp = NewVehicle->GetPCCVehicleMovementComponent();
	UPCCWheelInfo* wheelobjF = wheelSettingsFront.GetDefaultObject();
	UPCCWheelInfo* wheelobjB = wheelSettingsBack.GetDefaultObject();
	TArray<FWheelSetup> tires;
	if (wheelSettingsFront != nullptr)
	{
		FWheelSetup wheelFL;
		//Left
		wheelFL.WheelClass = wheelobjF->WheelSettings.CustomWheel;
		wheelFL.BoneName = wheelobjF->WheelSettings.BoneNameLeft;
		wheelFL.AdditionalOffset = wheelobjF->WheelSettings.AdditionalOffsetLeft;
		wheelFL.bDisableSteering = wheelobjF->WheelSettings.bDisableSteering;
		tires.Add(wheelFL);

		FWheelSetup wheelFR;
		//Right
		wheelFR.WheelClass = wheelobjF->WheelSettings.CustomWheel;
		wheelFR.BoneName = wheelobjF->WheelSettings.BoneNameRight;
		wheelFR.AdditionalOffset = wheelobjF->WheelSettings.AdditionalOffsetRight;
		wheelFR.bDisableSteering = wheelobjF->WheelSettings.bDisableSteering;
		tires.Add(wheelFR);
	}

	if (wheelSettingsBack != nullptr)
	{
		FWheelSetup wheelBL;

		//Left
		wheelBL.WheelClass = wheelobjB->WheelSettings.CustomWheel;
		wheelBL.BoneName = wheelobjB->WheelSettings.BoneNameLeft;
		wheelBL.AdditionalOffset = wheelobjB->WheelSettings.AdditionalOffsetLeft;
		wheelBL.bDisableSteering = wheelobjB->WheelSettings.bDisableSteering;
		tires.Add(wheelBL);

		FWheelSetup wheelBR;
		//Right
		wheelBR.WheelClass = wheelobjB->WheelSettings.CustomWheel;
		wheelBR.BoneName = wheelobjB->WheelSettings.BoneNameRight;
		wheelBR.AdditionalOffset = wheelobjB->WheelSettings.AdditionalOffsetRight;
		wheelBR.bDisableSteering = wheelobjB->WheelSettings.bDisableSteering;
		tires.Add(wheelBR);

	}	
	movementcomp->WheelSetups = tires;
	movementcomp->CreateVehicle();
	movementcomp->RecreatePhysicsState();

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8474b73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8474b73](https://forums.unrealengine.com/u/anonymous_user_c8474b73)\
**Post date:** [December 17, 2019, 2:46pm UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/7 "2019-12-17T14:46:45Z")

</div>

and thisis the error I currently get:

```
+ Primitive	0x0000021a7926b040 (Name=0x0000021a3991f9c4 "VehicleMesh")	UPrimitiveComponent * {UE4Editor-Engine.dll!USkeletalMeshComponent}
+ Primitive->Bounds	{Origin={X=nan Y=nan Z=nan } BoxExtent={X=nan Y=nan Z=nan } SphereRadius=nan }	FBoxSphereBounds
+ Primitive->Bounds.BoxExtent	{X=nan Y=nan Z=nan }	FVector
+ Primitive->Bounds.Origin	{X=nan Y=nan Z=nan }	FVector
		Primitive->Bounds.SphereRadius	nan	float
+ UpdateParams	{Scene=0x0000021aa0340440 {World=0x0000021ae8e10b80 (Name=0x0000021a3991ec4c "TestMap") FXSystem=0x0000021aee6334c0 {...} ...} ...}	FScene::UpdatePrimitiveTransform::__l17::FPrimitiveUpdateParams
+ UpdateParams.LocalBounds	{Origin={X=nan Y=nan Z=nan } BoxExtent={X=nan Y=nan Z=nan } SphereRadius=nan }	FBoxSphereBounds
+ this	0x0000021aa0340440 {World=0x0000021ae8e10b80 (Name=0x0000021a3991ec4c "TestMap") FXSystem=0x0000021aee6334c0 {...} ...}	FScene *

```

it seems like the bounding box doesn’t get generated when I use the RecreatePhysicsState.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8474b73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8474b73](https://forums.unrealengine.com/u/anonymous_user_c8474b73)\
**Post date:** [December 17, 2019, 2:46pm UTC](https://forums.unrealengine.com/t/physics-go-haywire-and-inconsistent-when-using-recreatephysicsstate/459623/8 "2019-12-17T14:46:46Z")

</div>

dunno if the reply is in review. if it is sorry for the double reply.  
`UPCCVehicleMovementComponent\* movementcomp = NewVehicle-\>GetPCCVehicleMovementComponent();  
UPCCWheelInfo\* wheelobjF = wheelSettingsFront.GetDefaultObject();  
UPCCWheelInfo\* wheelobjB = wheelSettingsBack.GetDefaultObject();

```
if (wheelSettingsFront != nullptr)
{
	//Left
	movementcomp->WheelSetups[0].WheelClass = wheelobjF->WheelSettings.CustomWheel;
	movementcomp->WheelSetups[0].BoneName = wheelobjF->WheelSettings.BoneNameLeft;
	movementcomp->WheelSetups[0].AdditionalOffset = wheelobjF->WheelSettings.AdditionalOffsetLeft;
	movementcomp->WheelSetups[0].bDisableSteering = wheelobjF->WheelSettings.bDisableSteering;

	//Right
	movementcomp->WheelSetups[1].WheelClass = wheelobjF->WheelSettings.CustomWheel;
	movementcomp->WheelSetups[1].BoneName = wheelobjF->WheelSettings.BoneNameRight;
	movementcomp->WheelSetups[1].AdditionalOffset = wheelobjF->WheelSettings.AdditionalOffsetRight;
	movementcomp->WheelSetups[1].bDisableSteering = wheelobjF->WheelSettings.bDisableSteering;
}

if (wheelSettingsBack != nullptr)
{
	//Left
	movementcomp->WheelSetups[2].WheelClass = wheelobjB->WheelSettings.CustomWheel;
	movementcomp->WheelSetups[2].BoneName = wheelobjB->WheelSettings.BoneNameLeft;
	movementcomp->WheelSetups[2].AdditionalOffset = wheelobjB->WheelSettings.AdditionalOffsetLeft;
	movementcomp->WheelSetups[2].bDisableSteering = wheelobjB->WheelSettings.bDisableSteering;

	//Right
	movementcomp->WheelSetups[3].WheelClass = wheelobjB->WheelSettings.CustomWheel;
	movementcomp->WheelSetups[3].BoneName = wheelobjB->WheelSettings.BoneNameRight;
	movementcomp->WheelSetups[3].AdditionalOffset = wheelobjB->WheelSettings.AdditionalOffsetRight;
	movementcomp->WheelSetups[3].bDisableSteering = wheelobjB->WheelSettings.bDisableSteering;
}
movementcomp->CreateVehicle();
movementcomp->RecreatePhysicsState();`

```
