Can't attach camera to capsule component

I’m getting the error that = on line 70 in MyCharacter.ccp is left operand?

MyCharacter.ccp :

// Fill out your copyright notice in the Description page of Project Settings.

#include "MyCharacter.h"
#include "Components/InputComponent.h"
#include "Atomic.h"
#include "Camera/CameraComponent.h"
#include "Components/SceneComponent.h"
#include "GameFramework/Character.h"





// Sets default values
AMyCharacter::AMyCharacter()
{
 	// 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 AMyCharacter::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	
	InputComponent->BindAxis("MoveForward", this, &AMyCharacter::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &AMyCharacter::MoveRight);
	InputComponent->BindAxis("Turn", this, &AMyCharacter::AddControllerYawInput);
	InputComponent->BindAxis("LookUp", this, &AMyCharacter::AddControllerPitchInput);
}

void AMyCharacter::MoveForward(float InInput)
{
	FRotator rotation = GetControlRotation();
	rotation.Pitch = 0;

	FVector MovementDirection = FRotationMatrix(rotation).GetScaledAxis(EAxis::X);
	AddMovementInput(MovementDirection, InInput);
}

void AMyCharacter::MoveRight(float InInput)
{
	FRotator rotation = GetControlRotation();
	rotation.Pitch = 0;

	FVector MovementDirection = FRotationMatrix(rotation).GetScaledAxis(EAxis::Y);
	AddMovementInput(MovementDirection, InInput);
}

AMyCharacter::AMyCharacter(const FObjectInitializer & ObjectInitializer)
	: Super(ObjectInitializer)
{
	// Create a CameraComponent 
	FirstPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FirstPersonCamera"));
	FirstPersonCameraComponent->AttachTo = GetCapsuleComponent();
}

MyCharacter.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Camera/CameraComponent.h"
#include "MyCharacter.generated.h"


UCLASS()
class MYPROJECT_API AMyCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AMyCharacter();

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;

protected:
	UFUNCTION()
		void MoveForward(float InInput);
	UFUNCTION()
		void MoveRight(float InInput);

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
		UCameraComponent* FirstPersonCameraComponent;

	AMyCharacter(const FObjectInitializer& ObjectInitializer);
};

Hi Ranhay,

AttachTo is a function, so you need to pass arguments to it rather than using the equal operand. Documentation Link

If you are in the constructor (like in your case), I recommend doing it like this:

FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
if (FirstPersonCameraComponent ) {
FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
}

now it says attachobjectcomp is unidentified

now it says attachobjectcomp is unidentified

Sorry about that, updated with your variable name

Try adding the include for capsule component at the top of the CPP file: #include “Components/CapsuleComponent.h”

now it says on the UCapsuleComponent is incompatible with parameter of type USceneComponent