Hello there. The problem is the following - trying to use default SetWheelClass funtion using Blueprints and CPP makes the wheel behave strangely, seemingly suspension stops working. After some digging and using CPP more, anything that re-initializes Suspension or Wheel (using the same methods from UChaosVehicleSimulation) screws the wheels until ResetVehicleState is used, but then the wheels go back to default parameters.
According to vehicle debugging, wheel that was re-initialized has 0 N load.
Before wheel change
I found a hacky way to do this in (UE 5.2) C++:
// Create a new FChaosWheelSetup for each wheel you want to replace
FChaosWheelSetup flSetup = FChaosWheelSetup();
brSetup.WheelClass = frontWheelClass;
brSetup.BoneName = FName("Phys_Wheel_FL");
// Replace the wheel setup defaults for each wheel in VehicleMovementComp
movementComponent_->WheelSetups[0] = flSetup;
// Reset the vehicle to re-initialize the wheels
movementComponent_->ResetVehicle();
Same thing here. Thanks for the reply, you save me some time
If you don’t want to hardcode the bone names there, you could simply use the existing ones. Here’s my code (for a three wheeled vehicle):
CPP_LosChaosWheeledVehicleMovementComponent.h:
class LOS_API UCPP_LosChaosWheeledVehicleMovementComponent : public UChaosWheeledVehicleMovementComponent
UFUNCTION()
void ChangeWheels(TSubclassOf<UChaosVehicleWheel> FrontWheelClass, TSubclassOf<UChaosVehicleWheel> RearWheelClass);
CPP_LosChaosWheeledVehicleMovementComponent.cpp:
void UCPP_LosChaosWheeledVehicleMovementComponent::ChangeWheels(TSubclassOf<UChaosVehicleWheel> FrontWheelClass, TSubclassOf<UChaosVehicleWheel> RearWheelClass)
// Create a new FChaosWheelSetup for each wheel you want to replace
FChaosWheelSetup FrontWheelSetup = FChaosWheelSetup();
FrontWheelSetup.WheelClass = FrontWheelClass;
FrontWheelSetup.BoneName = this->WheelSetups[0].BoneName;
FChaosWheelSetup LeftWheelSetup = FChaosWheelSetup();
LeftWheelSetup.WheelClass = RearWheelClass;
LeftWheelSetup.BoneName = this->WheelSetups[1].BoneName;
FChaosWheelSetup RightWheelSetup = FChaosWheelSetup();
RightWheelSetup.WheelClass = RearWheelClass;
RightWheelSetup.BoneName = this->WheelSetups[2].BoneName;
// Replace the wheel setup defaults for each wheel in VehicleMovementComp
this->WheelSetups[0] = FrontWheelSetup;
this->WheelSetups[1] = LeftWheelSetup;
this->WheelSetups[2] = RightWheelSetup;
// Reset the vehicle to re-initialize the wheels
this->ResetVehicle();
Huge thanks to both you and @diego.ba7op. I somehow did the same thing even before starting that thread, but my code did not work xD. Changing wheel setup is a proper solution because Chaos vehicles actually use them to create ingame object anywa. So for anyone who will stumble upon that thread summary goes as following:
Access to wheel setup and potentially vehicle setup will allow you to change almost all vehicle data you may want. Beware though that you will need to re-init the vehicle which will nullify velocity and contoller inputs.