Added a Camera, now game crashes (C++)

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;

};

Ok, apparently, the camera that I made just doesn’t exist at all to the character. Just a bit of possibly helpful information

You might want to move the code concerning your UCameraComponent into Acppcharacter::BeginPlay(). Also you would want to add the camera component as the current view target. One possible way is the following:

Acppcharacter::BeginPlay(){
    Super::BeginPlay();

    // not certain what you want for these values...
    FVector CamLocation = FVector(0,0,0); 
    FRotator CamRotation = FRotator(0,0,0);
    
    ACameraActor* CamActor = GetWorld()->SpawnActor<ACameraActor>(ACameraActor::StaticClass(), CamLocation, CamRotation);
    FPSCameraComponent = CamActor->GetCameraComponent();
    FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
    FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
    FPSCameraComponent->bUsePawnControlRotation = true;
    
    APlayerController* PlayerController = Cast<APlayerController>(Controller);
    if(PlayerController) PlayerControlller->PlayerCameraManager->SetViewTarget(CamActor));
}

One possible reason as to why the crash is occuring is that the capsule component might not actually exist/have a valid memory address during the calling of Acppcharacter::SetupPlayerInputComponent(). I am not an expert though.