I am trying to follow along with a tutorial that was designed for UE4. However, I was wanting to play around with UE5 (since it just came out). I was able to find some info in order to change some of the objects around to be compatible with UE5. But, I cannot seem to get the skeletal mesh to render either in the editor or in the game.
(I included the plugin for Chaos Vehicle)
Here is a copy of the C++ code for the vehicle class:
VehiclePawn.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "WheeledVehiclePawn.h"
#include "VehiclePawn.generated.h"
/**
*
*/
UCLASS()
class FOODTRUCKTURFWAR_API AVehiclePawn : public AWheeledVehiclePawn
{
GENERATED_BODY()
public:
AVehiclePawn();
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
// Control vehicle movement
void ApplyThrottle(float ThrottleValue);
void ApplySteering(float SteeringValue);
// Control camera movement
void ApplyLookUp(float LookUp);
void ApplyLookRight(float LookRight);
// Handbrake controls
void OnHandbrakePressed();
void OnHandbrakeReleased();
// Primary Fire Controls
void OnPrimaryFirePressed();
void OnPrimaryFireReleased();
// Secondart Fire Controls
void OnSecondaryFirePressed();
void OnSecondaryFireReleased();
// TurboBoost Controls
void OnTurboBoostPressed();
void OnTurboBoostReleased();
void UpdateInAirControl(float DeltaTime);
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* SpringArm;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* Camera;
};
VehiclePawn.cpp:
#include "VehiclePawn.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
#include "ChaosWheeledVehicleMovementComponent.h"
static const FName NAME_SteeringInput("Steering");
static const FName NAME_ThrottleInput("Throttle");
static const FName NAME_Handbrake("Handbrake");
static const FName NAME_LookUp("LookUp");
static const FName NAME_LookRight("LookRight");
static const FName NAME_TurboBoost("TurboBoost");
static const FName NAME_PrimaryFire("PrimaryFire");
static const FName NAME_SecondaryFire("SecondaryFire");
AVehiclePawn::AVehiclePawn()
{
UChaosWheeledVehicleMovementComponent* VehicleMovComp = CastChecked<UChaosWheeledVehicleMovementComponent>(GetVehicleMovement());
//Torque setup
VehicleMovComp->EngineSetup.MaxRPM = 5700.f;
VehicleMovComp->EngineSetup.TorqueCurve.GetRichCurve()->Reset();
// Starting at 0 RPM we will have 400 lbs of torque
VehicleMovComp->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(0.f, 400.f);
// Starting at 2000 RPM we will have 500 lbs of torque
VehicleMovComp->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(2000.f, 500.f);
// Starting at 5800 RPM we will have 400 lbs of torque
VehicleMovComp->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(5800.f, 400.f);
//Adjust The steering
VehicleMovComp->SteeringSetup.SteeringCurve.GetRichCurve()->Reset();
// Max Steering at 0 Mph is 1
VehicleMovComp->SteeringSetup.SteeringCurve.GetRichCurve()->AddKey(0.0f, 1.0f);
// Max Steering at 40 Mph is 0.7
VehicleMovComp->SteeringSetup.SteeringCurve.GetRichCurve()->AddKey(40.0f, 0.7f);
// Max Steering at 120 Mph is 0.6
VehicleMovComp->SteeringSetup.SteeringCurve.GetRichCurve()->AddKey(120.0f, 0.6f);
//Differential Setup
VehicleMovComp->DifferentialSetup.DifferentialType = EVehicleDifferential::AllWheelDrive;
VehicleMovComp->DifferentialSetup.FrontRearSplit = 0.65;
//Automatic Gear Box Setup
VehicleMovComp->TransmissionSetup.bUseAutomaticGears = true;
VehicleMovComp->TransmissionSetup.GearChangeTime = 0.15f;
VehicleMovComp->TransmissionSetup.bUseAutoReverse = true;
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
SpringArm->SetupAttachment(RootComponent);
SpringArm->TargetArmLength = 800.0f;
SpringArm->bUsePawnControlRotation = true;
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("ChaseCamera"));
Camera->SetupAttachment(SpringArm, USpringArmComponent::SocketName);
Camera->FieldOfView = 90.0f;
}
void AVehiclePawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
UpdateInAirControl(DeltaTime);
}
void AVehiclePawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// Bind Steering and throttle controls
PlayerInputComponent->BindAxis(NAME_ThrottleInput, this, &AVehiclePawn::ApplyThrottle);
PlayerInputComponent->BindAxis(NAME_SteeringInput, this, &AVehiclePawn::ApplySteering);
// Bind Camera controls
PlayerInputComponent->BindAxis(NAME_LookUp, this, &AVehiclePawn::ApplyLookUp);
PlayerInputComponent->BindAxis(NAME_LookRight, this, &AVehiclePawn::ApplyLookRight);
// Bind Handbrake controls
PlayerInputComponent->BindAction(NAME_Handbrake, IE_Pressed, this, &AVehiclePawn::OnHandbrakePressed);
PlayerInputComponent->BindAction(NAME_Handbrake, IE_Released, this, &AVehiclePawn::OnHandbrakeReleased);
// Bind Turbo Controls
PlayerInputComponent->BindAction(NAME_TurboBoost, IE_Pressed, this, &AVehiclePawn::OnTurboBoostPressed);
PlayerInputComponent->BindAction(NAME_TurboBoost, IE_Released, this, &AVehiclePawn::OnTurboBoostReleased);
// Bind Primary Fire Controls
PlayerInputComponent->BindAction(NAME_PrimaryFire, IE_Pressed, this, &AVehiclePawn::OnPrimaryFirePressed);
PlayerInputComponent->BindAction(NAME_PrimaryFire, IE_Released, this, &AVehiclePawn::OnPrimaryFireReleased);
// Bind Primary Fire Controls
PlayerInputComponent->BindAction(NAME_SecondaryFire, IE_Pressed, this, &AVehiclePawn::OnSecondaryFirePressed);
PlayerInputComponent->BindAction(NAME_SecondaryFire, IE_Released, this, &AVehiclePawn::OnSecondaryFireReleased);
}
void AVehiclePawn::ApplyThrottle(float ThrottleValue)
{
GetVehicleMovementComponent()->SetThrottleInput(ThrottleValue);
}
void AVehiclePawn::ApplySteering(float SteeringValue)
{
GetVehicleMovementComponent()->SetSteeringInput(SteeringValue);
}
void AVehiclePawn::ApplyLookUp(float LookUp)
{
if (LookUp != 0.f) {
AddControllerPitchInput(LookUp);
}
}
void AVehiclePawn::ApplyLookRight(float LookRight)
{
if (LookRight != 0.f) {
AddControllerYawInput(LookRight);
}
}
void AVehiclePawn::OnHandbrakePressed()
{
GetVehicleMovementComponent()->SetHandbrakeInput(true);
}
void AVehiclePawn::OnHandbrakeReleased()
{
GetVehicleMovementComponent()->SetHandbrakeInput(false);
}
I also am using the "City Sample Vehicles" pack from the marketplace and I have assigned the vehicle skeletal mesh in the blueprint:
As you can see the truck is not rendering in the viewport. It also does not render when I play the game. I know that the skeletal mesh works because it comes from a blueprint that works fine. I have tried to compare my code to the BP, but cannot find anything that could be causing it (that being said there is a LOT of stuff to compare, so I very well might be missing something).
Any help would be MUCH appreciated.
thanks in advance,
Brunke