Download

Vehicle 6 wheels in c++

I am using WheeledVehicleMovementComponent.h instead of WheeledVehicleMovementComponent4W.h for a 6-wheeled vehicle, but get this error of unreal:

This is the beginning of my code



#include "MyProject2.h"
#include "MyProject2Pawn.h"
#include "MyProject2WheelFront.h"
#include "MyProject2WheelRear.h"
#include "MyProject2Hud.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
#include "Vehicles/WheeledVehicleMovementComponent.h"
#include "Engine/SkeletalMesh.h"
#include "Engine.h"
// Needed for VR Headset
#include "IHeadMountedDisplay.h"

const FName AMyProject2Pawn::LookUpBinding("LookUp");
const FName AMyProject2Pawn::LookRightBinding("LookRight");

#define LOCTEXT_NAMESPACE "VehiclePawn"

AMyProject2Pawn::AMyProject2Pawn(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// Car mesh
	static ConstructorHelpers::FObjectFinder<USkeletalMesh> CarMesh(TEXT("/Game/Bus/busA.busA"));
	GetMesh()->SetSkeletalMesh(CarMesh.Object);

	static ConstructorHelpers::FClassFinder<UObject> AnimBPClass(TEXT("/Game/Bus/BusAnimBP"));
	GetMesh()->SetAnimInstanceClass(AnimBPClass.Class);

	// Simulation
	UWheeledVehicleMovementComponent* Vehicle = CastChecked<UWheeledVehicleMovementComponent>(GetVehicleMovement());



	Vehicle->WheelSetups[0].WheelClass = UMyProject2WheelFront::StaticClass();
	Vehicle->WheelSetups[0].BoneName = FName("e1");
	Vehicle->WheelSetups[0].AdditionalOffset = FVector(0.f, -12.f, 0.f);

	Vehicle->WheelSetups[1].WheelClass = UMyProject2WheelFront::StaticClass();
	Vehicle->WheelSetups[1].BoneName = FName("d1");
	Vehicle->WheelSetups[1].AdditionalOffset = FVector(0.f, 12.f, 0.f);

	Vehicle->WheelSetups[2].WheelClass = UMyProject2WheelRear::StaticClass();
	Vehicle->WheelSetups[2].BoneName = FName("e2");
	Vehicle->WheelSetups[2].AdditionalOffset = FVector(0.f, -12.f, 0.f);

	Vehicle->WheelSetups[3].WheelClass = UMyProject2WheelRear::StaticClass();
	Vehicle->WheelSetups[3].BoneName = FName("d2");
	Vehicle->WheelSetups[3].AdditionalOffset = FVector(0.f, 12.f, 0.f);

	Vehicle->WheelSetups[4].WheelClass = UMyProject2WheelRear::StaticClass();
	Vehicle->WheelSetups[4].BoneName = FName("e3");
	Vehicle->WheelSetups[4].AdditionalOffset = FVector(0.f, -12.f, 0.f);

	Vehicle->WheelSetups[5].WheelClass = UMyProject2WheelRear::StaticClass();
	Vehicle->WheelSetups[5].BoneName = FName("d3");
	Vehicle->WheelSetups[5].AdditionalOffset = FVector(0.f, 12.f, 0.f);
         ...
         


Can anyone help me?

You’re trying to access WheelSetups[4] when it doesn’t exist, you need to initialize that array element to something.

Sorry for my English, I am Brazilian. How can I do this? I do not see how to change this in the template unreal. The fact is that if you leave four wheel works perfectly. Is there any easier way to make a vehicle with more than four wheels?

for ( int32 WheelIdx = 0; WheelIdx < 4; ++WheelIdx )
You can see this sentence in Line 586 of WheeledVehicleMovementComponent.cpp