I was following the Unreal Engine FPS tutorial, and got to the point where i added the camera. But now when I try to play, my entire editor crashes. The code itself says it doesn’t ave any errors, but it still doesn’t work.
cppcharacter.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "cppcharacter.h"
// Sets default values
Acppcharacter::Acppcharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void Acppcharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void Acppcharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void Acppcharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// Set up movement bindings
PlayerInputComponent->BindAxis("MoveForward", this, &Acppcharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &Acppcharacter::MoveRight);
PlayerInputComponent->BindAxis("Turn", this, &Acppcharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &Acppcharacter::AddControllerPitchInput);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &Acppcharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &Acppcharacter::EndJump);
FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
FPSCameraComponent->bUsePawnControlRotation = true;
}
}
void Acppcharacter::MoveForward(float Value)
{
// Find out the "Forward" movement direction
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
void Acppcharacter::MoveRight(float Value)
{
// Find out the "Right" movement direction
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, Value);
}
void Acppcharacter::StartJump()
{
bPressedJump = true;
}
void Acppcharacter::EndJump()
{
bPressedJump = false;
}
cppcharacter.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Components/CapsuleComponent.h"
#include "Camera/CameraComponent.h"
#include "cppcharacter.generated.h"
UCLASS()
class CPPTEST_API Acppcharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
Acppcharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION()
void MoveForward(float Value);
UFUNCTION()
void MoveRight(float Value);
UFUNCTION()
void StartJump();
UFUNCTION()
void EndJump();
UPROPERTY(VisibleAnywhere)
UCameraComponent* FPSCameraComponent;
};