Change Tire on Runtime (BP/with a tiny bit of C++)

Updated Tutorial ;
https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1604103-updated-tutorial-4-21-update-tyre-data-on-runtime-popping-tires-c-bp

Hey everyone,
So today i figured out how to change wheels on runtime. So you dont have to go trough the same annoyance i went trough heres how to set it up.

Instructions:
1 : click file -> new C++ Class -> BlueprintFunctionLibrary (in my case i named it TireLib)
2 : After that head over to your (Projectname).build.cs inside visual studio (Game/Projectname/Source/Name/Projectname.Build.cs)
3 : Make sure “PhysXVehicles” is in the dependencys (seen in screenshot)
4 : Populate the .hFile of your library (step 1)




#include "WheeledVehicleMovementComponent.h"




USTRUCT(BlueprintType)
struct FWheelSetupBP
{
    GENERATED_BODY()

        // The wheel class to use
        UPROPERTY(BlueprintReadWrite, Category = WheelSetup)
        TSubclassOf<UVehicleWheel> WheelClass;

    // Bone name on mesh to create wheel at
    UPROPERTY(BlueprintReadWrite, Category = WheelSetup)
        FName BoneName;

    // Additional offset to give the wheels for this axle.
    UPROPERTY(BlueprintReadWrite, Category = WheelSetup)
        FVector AdditionalOffset;

    // Disables steering regardless of the wheel data
    UPROPERTY(BlueprintReadWrite, Category = WheelSetup)
        bool bDisableSteering;
};




UCLASS()
class TESTCPP_API UTireLib : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

    UFUNCTION(BlueprintCallable)
    static void modifyTyreConfig(UWheeledVehicleMovementComponent* Component, TArray<FWheelSetupBP> Tyres);
};

Make sure to replace tirelib with your filename

5: lastly go into the c++ part of the libary we created and include



void UTireLib::modifyTyreConfig(UWheeledVehicleMovementComponent * Component, TArray<FWheelSetupBP> Tyres)
{
    TArray<FWheelSetup> CTyres;
    for (int i = 0; i < Tyres.Num(); i++)
    {
        FWheelSetup tire;
        tire.WheelClass = Tyres*.WheelClass;
        tire.BoneName = Tyres*.BoneName;
        tire.AdditionalOffset = Tyres*.AdditionalOffset;
        tire.bDisableSteering = Tyres*.bDisableSteering;
        CTyres.Add(tire);
    }
    Component->WheelSetups = CTyres;
    Component->CreateVehicle();
    Component->RecreatePhysicsState();
}


After that you just have to compile and you will be able to setup your new tire seen in the Bp example.

Thank you Moddinggear over on Discord for helping me with the C++ and the setup.

If you have questions or issues please let me know below.

Rewrote the code No compiling issue. Was a pain to find the Updated Classes but it worked.