Wheels Properties realtime

How to change wheels properties of vehicle in realtime, I`ve tried to change array of wheels but nothink helps:
Wheels.Reset();
for (int32 WheelIdx = 0; WheelIdx < WheelSetups.Num(); ++WheelIdx)
{
UVehicleWheel* Wheel = NewObject(this, WheelSetups[WheelIdx].WheelClass);
check(Wheel);
Wheel->MaxBrakeTorque = 0;
Wheels.Add(Wheel);
}
for (int32 WheelIdx = 0; WheelIdx < Wheels.Num(); ++WheelIdx)
{
Wheels[WheelIdx]->Init(this, WheelIdx);
}

Maybe I need something else?

1 Like

I`ve found the soultion, set new parameter then recreate phyicsState:

WheelSetups[0].WheelClass->GetDefaultObject<UVehicleWheel>()->MaxHandBrakeTorque = 0;
WheelSetups[1].WheelClass->GetDefaultObject<UVehicleWheel>()->MaxHandBrakeTorque = 0;
WheelSetups[2].WheelClass->GetDefaultObject<UVehicleWheel>()->MaxHandBrakeTorque = 0;
WheelSetups[3].WheelClass->GetDefaultObject<UVehicleWheel>()->MaxHandBrakeTorque = 0;
VehicleSetupTag++;
RecreatePhysicsState();

Where would I need to look to find the syntax for other wheel properties?
i.e. I want to be able to change properties in the Wheel Class such as Radius or Suspension Raise / Drop etc. or just swap the entire Wheel Class.

This thread is the most promising I found, but I have no idea how to go about any of it.

If you use Visua Studio just click Ctrl+Space after “->” and select need parameter.
If need, here is the list of Wheel properties and functions to use:

class UStaticMesh*	CollisionMesh;
	bool bDontCreateShape;
	bool bAutoAdjustCollisionSize;
	FVector Offset;
	float ShapeRadius;
	float ShapeWidth;
	float Mass;
	float DampingRate;
	float SteerAngle;
	bool bAffectedByHandbrake;
	class UTireType* TireType;
	float LatStiffMaxLoad;
	float LatStiffValue;
	float LongStiffValue;
	float SuspensionForceOffset;
	float SuspensionMaxRaise;
	float SuspensionMaxDrop;
	float SuspensionNaturalFrequency;
	float SuspensionDampingRatio;
	float MaxBrakeTorque;
	float MaxHandBrakeTorque;
	class UWheeledVehicleMovementComponent* VehicleSim;
	int32 WheelIndex;
	float DebugLongSlip;
	float DebugLatSlip;
	float DebugNormalizedTireLoad;
	float DebugWheelTorque;
	float DebugLongForce;
	float DebugLatForce;
	FVector Location;
	FVector OldLocation;
	FVector Velocity;
	float GetSteerAngle();
	float GetRotationAngle();
	float GetSuspensionOffset();
	UPhysicalMaterial* GetContactSurfaceMaterial();

I’m working with the VehicleGame demo from the learning tab.
Oddly, if I run your code from the second post (1 answer):

GetVehicleMovement()->VehicleSetupTag++;
GetVehicleMovement()->RecreatePhysicsState();

My car starts colliding with itself and just goes ballistic.

Edit: As for Code Suggestion/Ctrl+Space (“Intellisense” I guess) - I now ran “Generate VS Project Files” (rightclick on UE4 project file) and that part works finally (it compiled before, but not having code suggestion was just horrible).

Where do you use wheels recreating, and one additional moment when you use RecreatePhysicsState is recreates physics state, and the engine recallect all physics data and make new physcs state, as a result your car will lose all current physics force.

There only some parameters of car that you can change in realtime: EngineSetup, DifferentialSetup, TransmissionSetup, DragCoeficcient, mass, InertiaTensorScale, AckermannAccuracy, SteeringCurve and TorqueCurve, Inputs, DragArea

Speaking about wheels you could only change the frictionscale:

VehicleMovement->Wheels[i]->TireType->SetFrictionScale(newfrictionScale);

only some parameters of car that you
can change in realtime […]. Speaking about wheels you could only change the frictionscale

I’m not sure I understand. Are you saying that most of the parameters you posted before (such as ShapeRadius; ShapeWidth etc.) can’t be modified at all in realtime?

Shouldn’t that work?

GetVehicleMovement()->Wheels[0]->ShapeRadius = 10;

or (Not sure what the difference is):

GetVehicleMovement()->WheelSetups[0].WheelClass->GetDefaultObject<UVehicleWheel>()->ShapeRadius = 85;

“Where do you use wheels recreating”

I am executing RecreatePhysicsState in the ABuggyPawn (a child of AWheeledVehicle class) inside an event triggered in the vehicle blueprint on key input (event is empty otherwise).

when you use RecreatePhysicsState is
recreates physics state, […] your
car will lose all current physics
force.

On execution (with or without change to any wheel parameters in the event), the car starts to jitter, shake and continuously gets bounced in the air (accompanied by collision sounds set up in the VehicleGame). It is a similar result to a car (or any other skeletal mesh) with auto-generated PhAT bodies.

After some fiddling around I made some progress on my journey to understand this stuff.

  1. I guess the difference between these two lines:

    GetVehicleMovement()->Wheels[0]->ShapeRadius = 10;

    GetVehicleMovement()->WheelSetups[0].WheelClass->GetDefaultObject()->ShapeRadius = 85;

Is the first being the current value and the second the configuration value applied on actor spawn. Changing the first doesn’t do anything, while changing the other actually changes the data asset, as well as does this line:

Wheels[0]->TireType->SetFrictionScale(1);

Frictionscale applies immediately at runtime, without the need to call recreate physics or setupVehicle() or anything, while ShapeRadius only applies after respawning the actor.

The problem though, as mentioned before: those changes apply to the actual data asset (if I go back to the editor, the data blueprints actually have changed). It’s interesting, but not very useable, as it changes the actual config and not an instance of it.

Is there a documentation on this or some examples in general? Feel really lost on this.

Edit:

For now, as my prototype works with a single vehicle setup, I have a WheelData + TireType asset for each wheel and one custom DataTable with default configuration values. On BeginPlay the data from the DataTable is being applied to the MovementComponent and thus saved in the WheelData/TireType assets which I treat as runtime storage. For shape I unfortunately have to destroy and respawn the actor once.

In the end I am able to have each wheel use different friction, mass and radius.
I guess if I wanted it to work with multiple vehicles, I’d have to dynamically allocate the WheelData/TireType.

Unfortunately with this setup I can only change wheel shape in a Garage Style environment, and wouldn’t be able to simulate for example a flat or lost tire while driving.

Yeap, you have right, unfortunately there is no documentation about this, and we have to look into this by ourselves.
Also, you could to look around SetupVehicle(), but it doesn`t work as needed. It also recreate your car and clear all its forces, but do not creat it after clearing.

As far as I tested, SetupVehicle() killed my inputs on the car, no idea why. It wouldn’t react to inputs any more.

But if it worked correctly, should it apply changes instantly the same way I am doing now with destroying/respawning my actor?

Also, going back to RecreatePhysicsState() - what exactly should this accomplish?

Basically what I’m asking is - what is RecreatePhysicsState() and SetupVehicle() supposed to do?

Hey everyone, I know this is an old thread, but I’m looking to change the wheels’ suspension damping rate. Was there a definitive answer to change these settings at runtime?