Unrecognized type 'UComponent' - type must be a UCLASS, USTRUCT or UENUM

Hi all, I’ve been sat on this error for a while now, I feel like I’ve exhausted some options - which makes me feel like its something incredibly simple :smiley: What am I doing wrong here?:

Unrecognized type ‘UWRCameraMovementComponent’ - type must be a UCLASS, USTRUCT or UENUM C:\Users\Me\Documents\UE\WR\Source\WR\Public\WRPlayer.h

The command ““C:\Program Files\Epic Games\UE_5.0EA\Engine\Build\BatchFiles\Build.bat” WREditor Win64 Development -Project=“C:\Users\Me\Documents\UE\WR\WR.uproject” -WaitMutex -FromMsBuild” exited with code 6. WR C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets 45

header:

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "WRPlayer.generated.h"

class UWRCameraMovementComponent;

UCLASS()
class WR_API AWRPlayer : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AWRPlayer();


protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;


public:	

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera Movement")
    UWRCameraMovementComponent* PawnMovement;

cpp:

#include "WRPlayer.h"
#include "WRCameraMovementComponent.h"

// Sets default values
AWRPlayer::AWRPlayer()
{
	//attach movement component
	PawnMovement = CreateDefaultSubobject<UWRCameraMovementComponent>(TEXT("Camera Movement Component"));
 }

Oh, wow… yep this did the trick…

Thank you Sir

Post your definition of UWRCameraMovementComponent class please (header file for that class).

I guess you are most likely missing UCLASS() before class definition.

Hi, thanks for getting back to me, here is the class:

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "WRCameraMovementComponent.generated.h"

class AWRPlayer;

UCLASS()
class WR_API AWRCameraMovementComponent : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AWRCameraMovementComponent();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

By adding the below at line 25 in WRPlayer.h:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera Movement")
	TSubclassOf<UWRCameraMovementComponent> PawnMovement;

I receive this error upon building:

Class 'UWRCameraMovementComponent' has an incorrect prefix, expecting 'AWRCameraMovementComponent'	WR	C:\Users\Me\Documents\UE\WR\Source\WR\Public\WRPlayer.	

Now, am I correct in thinking that because I am trying to add this movement component into my pawn class via ‘CreateDefaultSubobject’ it should not be ‘AWRCameraMovementComponent’ and instead ‘UWRCameraMovementComponent’ (UObject)?

You are welcome. Don’t forget to upvote the comments that helped you (the green thumb at the top of every comment) ^^.

class WR_API AWRCameraMovementComponent : public AActor
This is an actor class that cannot really be spawned in constructor, you would need to use SpawnActor during gameplay.

I reckon you want actor component, so you can attach it to your player, thus you would need to change the class name to UWRCameraMovementComponent (notice U vs A in the name) and derive from UActorComponent instead of AActor, this way you can add the component to your player actor.

Something like this (don’t forget to include header for actor component and chance constructor name):

#include "Components/ActorComponent.h"

 class WR_API UWRCameraMovementComponent : public UActorComponent

Here is nice overview of actors vs components Actors | Unreal Engine Documentation

Since question poster approved solution i convert it to answer and marked as solved ;]