UPROPERTY Issues

Hello there!

Recently I’ve decided to go back to the beginning of C++ instead of my usual blueprints route. I was following the tutorial A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums and I came across an issue I can’t seem to figure out on my own.

When adding the camera component my UPROPERTY gives the compiler error “Member Variable Declaration: Missing Variable Type”

I was hoping one of you could tell me what I’m missing or doing wrong.

Here is my FPSCharacter. H and FPS Character.CPP

UCLASS()
class VICTORIOUS512_API AFPSCharacter : public ACharacter
{
	GENERATED_BODY()
		AFPSCharacter(const FObjectInitializer& ObjectInitializer);

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

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 Val);
	UFUNCTION()
		void MoveRight(float Val);
	UFUNCTION()
		void OnStartJump();
	UFUNCTION()
		void OnStopJump();

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

// Separation

AFPSCharacter::AFPSCharacter()
{
 	// 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;


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

// Called when the game starts or when spawned
void AFPSCharacter::BeginPlay()
{
	Super::BeginPlay();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("We are using FPSCharacter!"));
	}
	
}

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

}

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

	InputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::OnStartJump);
	InputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::OnStopJump);

}
void AFPSCharacter::MoveForward(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		// find out which way is forward
		FRotator Rotation = Controller->GetControlRotation();
		// Limit pitch when walking or falling
		if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling())
		{
			Rotation.Pitch = 0.0f;
		}
		// add movement in that direction
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
		AddMovementInput(Direction, Value);
	}
}
void AFPSCharacter::MoveRight(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		// find out which way is right
		const FRotator Rotation = Controller->GetControlRotation();
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
		// add movement in that direction
		AddMovementInput(Direction, Value);
	}
}
void AFPSCharacter::OnStartJump()
{
	bPressedJump = true;
}
void AFPSCharacter::OnStopJump()
{
	bPressedJump = false;
}

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

You have an errant semi-colon after the UPROPERTY(...) macro.

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

When I remove the semi-colon(which I totally didn’t see, thank you), I get an error telling me to put it back and then a whole mess of things.

When trying to include the header for UCameraComponent in my header class, I get this Screenshot - edf48ee4a431c42c0daaad8c8f8c7d01 - Gyazo
I also tried removing the U as the API doc says for the class with no success.

Hmm, that’s the error the compiler generates when it doesn’t understand the type. In this case it doesn’t know what UCameraComponent is (either in the header or the cpp file).

You can either include the header for UCameraComponent in your header, or, since you’re only storing a pointer to a UCameraComponent in your header, you could forward declare it there and then include the header for UCameraComponent in your cpp file. Up to you :slight_smile:

That’s because that’s not the header for UCameraComponent. You can’t just assume header names, you need to use the API reference to look up types and find what header they’re in. In this case, it’s #include "Camera/CameraComponent.h".