I have been scouring the web and other resources. I have even reached out to Epic Games Staff and they wont even try to help me. There is no documentation regarding modification of the Vehicles Code. So either someone with extensive knowledge of C++ code needs to shed some light on this or there is no other way for me to achieve this (what I think should be a rather simple feature) modification. I want to take and expose the ChaosWheeledVehicleComponents VehicleDifferential setup so I can change between 2WD and 4WD using a “SetDifferential” Function. Here’s what I have so far. It compiles, it calls and executes, but it doesn’t change the DifferentialType.
Header File
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "ChaosWheeledVehicleMovementComponent.h"
#include "TransmissionSystem.h" // To reference "VehicleDifferential"
#include "VehicleSystemTemplate.h"
#include "VehicleUtility.h"
#include "IEIAdvancedVehicle.generated.h"
UENUM(BlueprintType)
enum class EAdvVehicleDifferential : uint8
{
UndefinedDrive,
AllWheelDrive,
FrontWheelDrive,
RearWheelDrive,
};
UCLASS(Blueprintable, ClassGroup = (Vehicles), meta = (BlueprintSpawnableComponent))
class IEIADVANCEDVEHICLES_API UIEIAdvancedVehicle : public UChaosWheeledVehicleMovementComponent
{
GENERATED_BODY()
public:
// Exposes a method to set the drivetrain configuration in Blueprints
UFUNCTION(BlueprintCallable, Category = "Vehicle|Drivetrain")
void SetDifferential(EAdvVehicleDifferential NewDifferential);
private:
// Maps the Blueprint enum to Chaos vehicle differential configurations
Chaos::EDifferentialType MapDifferentialType(EAdvVehicleDifferential NewDifferential) const;
};
Source File
#include "IEIAdvancedVehicle.h"
#include "ChaosWheeledVehicleMovementComponent.h"
#include "TransmissionSystem.h" // For Chaos::EDifferentialType
void UIEIAdvancedVehicle::SetDifferential(EAdvVehicleDifferential NewDifferential)
{
// Map the Blueprint enum to the Chaos differential type
Chaos::EDifferentialType NewDifferentialCpp = MapDifferentialType(NewDifferential);
// Validate vehicle simulation
if (!VehicleSimulationPT || !VehicleSimulationPT->PVehicle)
{
UE_LOG(LogTemp, Warning, TEXT("Vehicle simulation is not initialized."));
return;
}
auto& PVehicle = VehicleSimulationPT->PVehicle;
// Update the differential configuration
PVehicle->GetDifferential().AccessSetup().DifferentialType = NewDifferentialCpp;
// Apply changes through engine mechanisms, if any provided
// Remove the call to Reinitialize as it does not exist
}
Chaos::EDifferentialType UIEIAdvancedVehicle::MapDifferentialType(EAdvVehicleDifferential NewDifferential) const
{
switch (NewDifferential)
{
case EAdvVehicleDifferential::UndefinedDrive:
return Chaos::EDifferentialType::UndefinedDrive;
case EAdvVehicleDifferential::AllWheelDrive:
return Chaos::EDifferentialType::AllWheelDrive;
case EAdvVehicleDifferential::FrontWheelDrive:
return Chaos::EDifferentialType::FrontWheelDrive;
case EAdvVehicleDifferential::RearWheelDrive:
return Chaos::EDifferentialType::RearWheelDrive;
default:
// Log warning for unsupported configuration
UE_LOG(LogTemp, Warning, TEXT("Unsupported differential type provided."));
return Chaos::EDifferentialType::AllWheelDrive; // Default to AWD
}
}
Please, I am literally begging at this point. I have spent months trying to figure this out and I feel I am close, I am just very limited with C++ Code knowledge.