My C++ class keeps crashing the engine when opening my project can someone help

Hello, this is my first time posting here (I think) and I’ve run into a crash that I just can’t figure out. I have a C++ class called PlayerCharacter.cpp and its respective .h file.

So far, on the .h file I have added this:



UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class UStaticMeshComponent* PlayerMesh;

UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class UCameraComponent* GameCamera;

UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class USpringArmComponent* CameraSpringArm;

That code is right below the constructor of the .h file

Now in the constructor for the .cpp class I have this:



APlayerCharacter::APlayerCharacter()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

PlayerMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlayerMesh"));
PlayerMesh->SetupAttachment(RootComponent);

CameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Camera"));
CameraSpringArm->SetupAttachment(RootComponent);

GameCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); //this here is the error line by the looks of it
GameCamera->SetupAttachment(CameraSpringArm);
}


I did make some edits to the includes because I kept getting a red squiggle for the spring arm so I #include “GameFramework/SpringArmComponent.h”
I tried to compile and still got a compile error so I figured maybe it’s the camera? So I #include “Camera/CameraComponent.h”


#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "PlayerCharacter.h"

After doing the include for the camera component the compile crashed the whole game with this error message:
Fatal error: [File: D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp] [Line: 3768] Default subobject CameraComponent Camera already exists for PlayerCharacter /Script/SpaceGame.Default__PlayerCharacter.

Already tried reconstructing binaries and I know if I delete the files and reconstruct the binaries the issue will go away, but I’m going to run into it again when trying to setup a camera. It’s saying that there already is a camera but there isn’t, this is my first pawn class/ blueprint and first C++ class for that matter and the blueprint doesn’t show a camera either so I don’t know where this other camera is coming from

The error message tells you everything. There is already a default subobject called “Camera” in PlayerCharacter class. The engine doesn’t like that you named both the SpringArmComponent and the CameraComponent “Camera”.