"CameraComponent can be garbage collected anytime" is preventing me from compiling

SurvivalCharacter.h:

#include "Camera/CameraComponent.h"
#include "GameFramework/Character.h"
#include "SurvivalCharacter.generated.h"

UCLASS()
class SURVIVALGAME_API ASurvivalCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	ASurvivalCharacter();
	
	UPROPERTY(EditAnywhere, Category = "Components");
	class UCameraComponent* CameraComponent;

SurvivalCharacter.cpp:

#include "SurvivalCharacter.h"
#include "Camera/CameraComponent.h";
#include "Components/SkeletalMeshComponent.h";

// Sets default values
ASurvivalCharacter::ASurvivalCharacter()
{
 	// 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;
	CameraComponent = CreateDefaultSubobject<UCameraComponent>("CameraComponent");
	CameraComponent->SetupAttachment(GetMesh());
	CameraComponent->bUsePawnControlRotation = true;

“CameraComponent can be garbage collected anytime” is preventing me from compiling. I read that giving an object a UPROPERTY would prevent this from happening. What am I doing wrong?

Found the issue. No semicolons after UPROPERTY

1 Like