This is something I’ve been struggling with for weeks now. Something as simple as just changing out the vehicle tire type within blueprints.
From what I can understant this is not possible without somehow exposing the values of the vehicle wheel in blueprints.
I have found other posts asking the same question and from those I got some code that from my understanding would create a blueprint node that could be used for this,
But currently I have no idea how to implement it.
This is the code I’ve found from another post, if anyone could explain to me how to implement this that’d be great.
VehicleGame.Build.cs
PrivateDependencyModuleNames.AddRange(
new string[] {
"Slate",
"SlateCore",
"PhysX",
}
);
class UVehicleMovementComponentBoosted4w
VehicleMovementComponentBoosted4w.h
/** Wheel Lat Stiff */
UFUNCTION(BlueprintCallable, Category = "Wheel")
void SetWheelLatStiff(int32 WheelIndex, float LatStiffValue, float LatStiffMaxLoad, float LongStiffValue, class UTireType* TireType);
/** Wheel Friction*/
UFUNCTION(BlueprintCallable, Category = "Wheel")
void SetWheelFrictionScale(int32 WheelIndex, class UTireType* TireType);
VehicleMovementComponentBoosted4w.cpp
#if WITH_PHYSX
#include "PxVehicleWheels.h"
#endif //WITH_PHYSX
void UVehicleMovementComponentBoosted4w::SetWheelLatStiff(int32 WheelIndex, float LatStiffValue, float LatStiffMaxLoad, float LongStiffValue, class UTireType* TireType)
{
if (WheelIndex >= 0 && LatStiffValue > 0.01 && LatStiffMaxLoad > 0.01 && LongStiffValue > 0.01 && Wheels.Num() > WheelIndex)
{
Wheels[WheelIndex]->LatStiffValue = LatStiffValue;
Wheels[WheelIndex]->LatStiffMaxLoad = LatStiffMaxLoad;
Wheels[WheelIndex]->LongStiffValue = LongStiffValue;
Wheels[WheelIndex]->TireType = TireType;
// init tire data
// physx::PxVehicleTireData PTireData;
physx::PxVehicleTireData PTireData;
PTireData.mType = Wheels[WheelIndex]->TireType ? Wheels[WheelIndex]->TireType->GetTireTypeID() : GEngine->DefaultTireType->GetTireTypeID();
PTireData.mLatStiffX = Wheels[WheelIndex]->LatStiffMaxLoad;
PTireData.mLatStiffY = Wheels[WheelIndex]->LatStiffValue;
PTireData.mLongitudinalStiffnessPerUnitGravity = Wheels[WheelIndex]->LongStiffValue;
PVehicle->mWheelsSimData.setTireData(WheelIndex, PTireData);
}
}
void UVehicleMovementComponentBoosted4w::SetWheelFrictionScale(int32 WheelIndex, class UTireType* TireType)
{
if (WheelIndex >= 0 && Wheels.Num() > WheelIndex)
{
Wheels[WheelIndex]->TireType = TireType;
// init tire data
// physx::PxVehicleTireData PTireData;
physx::PxVehicleTireData PTireData;
PTireData.mType = Wheels[WheelIndex]->TireType ? Wheels[WheelIndex]->TireType->GetTireTypeID() : GEngine->DefaultTireType->GetTireTypeID();
PTireData.mLatStiffX = Wheels[WheelIndex]->LatStiffMaxLoad;
PTireData.mLatStiffY = Wheels[WheelIndex]->LatStiffValue;
PTireData.mLongitudinalStiffnessPerUnitGravity = Wheels[WheelIndex]->LongStiffValue;
PVehicle->mWheelsSimData.setTireData(WheelIndex, PTireData);
}
}