void UWheeledVehicleMovementComponent4W::SetupVehicle()
{
	if (!UpdatedPrimitive)
	{
		return;
	}

	if (WheelSetups.Num() != 4)
	{
		PVehicle = NULL;
		PVehicleDrive = NULL;
		return;
	}

	for (int32 WheelIdx = 0; WheelIdx < WheelSetups.Num(); ++WheelIdx)
	{
		const FWheelSetup& WheelSetup = WheelSetups[WheelIdx];
		if (WheelSetup.BoneName == NAME_None)
		{
			return;
		}
	}

	// Setup the chassis and wheel shapes
	SetupVehicleShapes();

	// Setup mass properties
	SetupVehicleMass();

	// Setup the wheels
	PxVehicleWheelsSimData* PWheelsSimData = PxVehicleWheelsSimData::allocate(4);
	SetupWheels(PWheelsSimData);

	// Setup drive data
	PxVehicleDriveSimData4W DriveData;
	SetupDriveHelper(this, PWheelsSimData, DriveData);

	// Create the vehicle
	PxVehicleDrive4W* PVehicleDrive4W = PxVehicleDrive4W::allocate(4);
	check(PVehicleDrive4W);

	ExecuteOnPxRigidDynamicReadWrite(UpdatedPrimitive->GetBodyInstance(), [&] (PxRigidDynamic* PRigidDynamic)
	{
		PVehicleDrive4W->setup( GPhysXSDK, PRigidDynamic, *PWheelsSimData, DriveData, 0);
		PVehicleDrive4W->setToRestState();

		// cleanup
		PWheelsSimData->free();
	});
	
	PWheelsSimData = NULL;

	// cache values
	PVehicle = PVehicleDrive4W;
	PVehicleDrive = PVehicleDrive4W;

	SetUseAutoGears(TransmissionSetup.bUseGearAutoBox);
}
void UWheeledVehicleMovementComponent4W::SetupVehicle()
{
	if (WheelSetups.Num() != 4)
	{
		PVehicle = NULL;
		PVehicleDrive = NULL;
		return;
	}

	// Setup the chassis and wheel shapes
	SetupVehicleShapes();

	// Setup mass properties
	SetupVehicleMass();

	// Setup the wheels
	PxVehicleWheelsSimData* PWheelsSimData = PxVehicleWheelsSimData::allocate(4);
	SetupWheels(PWheelsSimData);

	// Setup drive data
	PxVehicleDriveSimData4W DriveData;
	SetupDriveHelper(this, PWheelsSimData, DriveData);

	// Create the vehicle
	PxVehicleDrive4W* PVehicleDrive4W = PxVehicleDrive4W::allocate(4);
	check(PVehicleDrive4W);

	PVehicleDrive4W->setup( GPhysXSDK, UpdatedComponent->BodyInstance.GetPxRigidDynamic(), *PWheelsSimData, DriveData, 0);
	PVehicleDrive4W->setToRestState();

	// cleanup
	PWheelsSimData->free();
	PWheelsSimData = NULL;

	// cache values
	PVehicle = PVehicleDrive4W;
	PVehicleDrive = PVehicleDrive4W;

	// MSS Using PxVehicle built-in automatic transmission for now. No reverse yet, have to fix that.
 //SetUseAutoGears(bUseGearAutoBox);
	SetUseAutoGears(true);
	//SetTargetGear(1, true);

	const int MaxSteeringSamples = FMath::Min(8, SteeringCurve.Num());
	for (int i = 0; i < 8; i++)
	{
		SteeringMap[i*2 + 0] = (i < MaxSteeringSamples) ? (SteeringCurve[i].InVal * MaxSteeringSpeed) : PX_MAX_F32;
		SteeringMap[i*2 + 1] = (i < MaxSteeringSamples) ? FMath::Clamp<float>(SteeringCurve[i].OutVal, 0.0f, 1.0f) : PX_MAX_F32;
	}
}