We’re facing a weird issue with Chaos Wheeled Vehicles. It looks like vehicles can override the torque distribution for wheels for other vehicles, changing their driving characteristics at a glance.
I’ve mostly tracked this down to the usage of the FSimpleWheelConfig. It looks like this is shared data, i.e. it’s only created once for the wheel CDO and then shared amongst all instances for wheel simulations:
Engine/Plugins/Experimental/ChaosVehiclesPlugin/Source/ChaosVehicles/Private/ChaosWheeledVehicleMovementComponent.cpp:1400
`UChaosVehicleWheel* Wheel = WheelSetups[WheelIdx].WheelClass.GetDefaultObject();
// create Dynamic states passing in pointer to their Static setup data
Chaos::FSimpleWheelSim WheelSim(&Wheel->GetPhysicsWheelConfig());`Now, the catch is that the CDO is of course “const”, and it’s stored as const in TVehicleSystem<>, BUT for some reason, TVehicleSystem<>:AccessSetup() returns a non-const reference to it! This breaks the whole const CDO contract, and I don’t see any documentation about why this happens and how this is guaranteed to be safe.
Now, as the wheel setup isn’t const anymore, there are several locations where the setup object is modified, like at
Engine/Plugins/Experimental/ChaosVehiclesPlugin/Source/ChaosVehicles/Private/ChaosWheeledVehicleMovementComponent.cpp:1425
WheelSim.AccessSetup().EngineEnabled = EngineEnable;
or at Engine/Plugins/Experimental/ChaosVehiclesPlugin/Source/ChaosVehicles/Private/ChaosWheeledVehicleMovementComponent.cpp:1508
PWheel.AccessSetup().TorqueRatio = TorqueRatio;
We’re especially suffering from the torque ratio, as different vehicles have different drivetrain setups, and this just “randomly” sets the value to whatever the most recent spawned vehicle wants it to be.
As the engine simulation uses the torque ratio, all vehicles are indirectly affected by this, at Engine/Plugins/Experimental/ChaosVehiclesPlugin/Source/ChaosVehicles/Private/ChaosWheeledVehicleMovementComponent.cpp:880
PWheel.SetDriveTorque(TorqueMToCm(TransmissionTorque) * PWheel.Setup().TorqueRatio);
Now, looking at this whole situation, I’m not sure if someone did mix up access to those values, as the FSimpleWheelSim PWheel itself has the same values declared as fields! So I wonder if the Setup() access is even correct and instead, the values should be set directly on the FSimpleWheelSim instances.
I’ve also looked into Perforce, and the most recent version of the vehicle simulation still has the same logic, so I guess this may happen on 5.5 as well.
I wonder, are my thoughs correct about this? Maybe I’m missing something crucial here.