Error C2065 confusion

Hi, so I’ve got a class inherited AActor and I’m attempting to add a capsule component to it but I keep getting error C2065 about the variable being unidentified.

The variable name is spelled correctly and I’ve included Classes/CapsuleComponent.h but the error persists. I’ve been driven slightly mad by this, can any one else?

I have the “Components/CapsuleComponent.h” included in the cpp. I’ve tried both and neither seems to work.

Nevermind. I’ve fixed it. It was embarrassing.

Pro tip kids. Make sure you’re declaring class variables in the class header, and not in a struct you’ve defined at the top of the header file.

My bad.

I can’t say for sure because you didn’t post any code but this is how an actor would be setup for a UCapsuleComponent in an Actor:

[.h]

#pragma once

#include "MyGame.h"
#include "GameFramework/Actor.h"
#include "Components/CapsuleComponent.h"
#include "MyActor.generated.h"

UCLASS()
class MYGAME_API AMyActor : public AActor
{
	GENERATED_BODY()
	
public:	
	AMyActor();
	virtual void BeginPlay() override;
    virtual void Tick( float DeltaTime );
	
	UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "My Actor")
	UCapsuleComponent *Collider;
	
};

[.cpp]

#include "MyActor.h"

AMyActor::AMyActor( )
{
	Collider = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Collider"));
	SetRootComponent(Collider);
	
}

void AMyActor::BeginPlay( )
{
	Super::BeginPlay( );
}

void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}